mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
[osdep] os_get_free_mem_in_mib
DOS and Linux implementation. Called in bfu/leds.c
This commit is contained in:
parent
e88325a7e7
commit
f8d08d1db3
@ -21,6 +21,7 @@
|
||||
#include "intl/libintl.h"
|
||||
#include "main/module.h"
|
||||
#include "main/timer.h"
|
||||
#include "osdep/osdep.h"
|
||||
#include "session/session.h"
|
||||
#include "terminal/draw.h"
|
||||
#include "terminal/tab.h"
|
||||
@ -219,45 +220,15 @@ static int
|
||||
draw_show_mem(struct session *ses, int xpos, int ypos, struct color_pair *color)
|
||||
{
|
||||
struct terminal *term = ses->tab->term;
|
||||
FILE *f;
|
||||
struct string text;
|
||||
int i;
|
||||
int length;
|
||||
char *pos;
|
||||
long ret = 0;
|
||||
|
||||
f = fopen("/proc/meminfo", "r");
|
||||
|
||||
if (!f) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (!feof(f)) {
|
||||
char buffer[128];
|
||||
|
||||
if (!fgets(buffer, 127, f)) {
|
||||
break;
|
||||
}
|
||||
if (strncmp(buffer, "MemAvailable:", sizeof("MemAvailable:")-1)) {
|
||||
continue;
|
||||
}
|
||||
if (sscanf(buffer, "MemAvailable:%ld", &ret) < 1) {
|
||||
ret = 0;
|
||||
break;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
if (ret < 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!init_string(&text)) {
|
||||
return 0;
|
||||
}
|
||||
add_format_to_string(&text, "[%ld MiB]", ret / 1024);
|
||||
add_format_to_string(&text, "[%ld MiB]", os_get_free_mem_in_mib());
|
||||
length = text.length;
|
||||
for (i = 0, pos = text.source; i < length; i++) {
|
||||
draw_char(term, xpos - length + i, ypos, pos[i], 0, color);
|
||||
|
@ -983,6 +983,18 @@ int dos_select(int n, fd_set *rs, fd_set *ws, fd_set *es, struct timeval *t, int
|
||||
}
|
||||
}
|
||||
|
||||
long
|
||||
os_get_free_mem_in_mib(void)
|
||||
{
|
||||
__dpmi_memory_info buffer;
|
||||
int ret = __dpmi_get_memory_information(&buffer);
|
||||
|
||||
if (ret) {
|
||||
return 0;
|
||||
}
|
||||
return buffer.total_available_bytes_of_virtual_memory_client / (1024 * 1024);
|
||||
}
|
||||
|
||||
#ifdef DOS_EXTRA_KEYBOARD
|
||||
|
||||
int dos_setraw(int ctl, int save)
|
||||
|
@ -74,6 +74,14 @@
|
||||
#include "util/string.h"
|
||||
|
||||
|
||||
#if !defined(CONFIG_OS_DOS) && !defined(CONFIG_OS_UNIX)
|
||||
long
|
||||
os_get_free_mem_in_mib(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_OS_DOS
|
||||
/* Set a file descriptor to non-blocking mode. It returns a non-zero value
|
||||
* on error. */
|
||||
|
@ -54,6 +54,7 @@ int can_resize_window(int);
|
||||
int can_open_os_shell(int);
|
||||
void set_highpri(void);
|
||||
char *tempname(const char *dir, const char *pfx, char *suff);
|
||||
long os_get_free_mem_in_mib(void);
|
||||
|
||||
#ifdef USE_OPEN_PREALLOC
|
||||
int open_prealloc(char *, int, int, off_t);
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
#include "osdep/system.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(CONFIG_GPM) && defined(HAVE_GPM_H)
|
||||
#include <gpm.h>
|
||||
#endif
|
||||
@ -155,5 +157,38 @@ resume_mouse(void *h)
|
||||
|
||||
set_handlers(gms->h, (select_handler_T) gpm_mouse_in, NULL, NULL, gms);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
long
|
||||
os_get_free_mem_in_mib(void)
|
||||
{
|
||||
FILE *f = fopen("/proc/meminfo", "r");
|
||||
long ret = 0;
|
||||
|
||||
if (!f) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (!feof(f)) {
|
||||
char buffer[128];
|
||||
|
||||
if (!fgets(buffer, 127, f)) {
|
||||
break;
|
||||
}
|
||||
if (strncmp(buffer, "MemAvailable:", sizeof("MemAvailable:")-1)) {
|
||||
continue;
|
||||
}
|
||||
if (sscanf(buffer, "MemAvailable:%ld", &ret) < 1) {
|
||||
ret = 0;
|
||||
break;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
if (ret < 1) {
|
||||
return 0;
|
||||
}
|
||||
return ret / 1024;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user