use long for meminfo_type elements
This commit is contained in:
@@ -46,18 +46,18 @@ typedef struct
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int total; /**< total memory (in kB) */
|
long total; /**< total memory (in kB) */
|
||||||
int cache; /**< memory in page cache (in kB) */
|
long cache; /**< memory in page cache (in kB) */
|
||||||
int buffers; /**< memory in buffer cache (in kB) */
|
long buffers; /**< memory in buffer cache (in kB) */
|
||||||
int free; /**< free memory (in kB) */
|
long free; /**< free memory (in kB) */
|
||||||
int shared; /**< ??? (in kB) */
|
long shared; /**< ??? (in kB) */
|
||||||
} meminfo_type;
|
} meminfo_type;
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char name[16]; /**< process name */
|
char name[16]; /**< process name */
|
||||||
int totl; /**< process memory usage (in kB) */
|
long totl; /**< process memory usage (in kB) */
|
||||||
int number; /**< incstances of the process */
|
int number; /**< incstances of the process */
|
||||||
} procinfo_type;
|
} procinfo_type;
|
||||||
|
|
||||||
|
|||||||
@@ -153,26 +153,29 @@ reread (int f, char *errmsg)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
static int
|
||||||
getentry (const char *tag, const char *bufptr)
|
getentry (const char *tag, const char *bufptr, long *value)
|
||||||
{
|
{
|
||||||
char *tail;
|
char *tail;
|
||||||
int len = strlen(tag);
|
int len = strlen(tag);
|
||||||
long retval;
|
long val;
|
||||||
|
|
||||||
while (bufptr != NULL) {
|
while (bufptr != NULL) {
|
||||||
if (*bufptr == '\n')
|
if (*bufptr == '\n')
|
||||||
bufptr++;
|
bufptr++;
|
||||||
if (!strncmp(tag, bufptr, len)) {
|
if (!strncmp(tag, bufptr, len)) {
|
||||||
retval = strtol(bufptr + len, &tail, 10);
|
errno = 0;
|
||||||
if (tail == bufptr + len)
|
val = strtol(bufptr + len, &tail, 10);
|
||||||
return -1;
|
if ((errno == 0) && (tail != bufptr + len)) {
|
||||||
|
*value = val;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return retval;
|
return FALSE;
|
||||||
}
|
}
|
||||||
bufptr = strchr(bufptr, '\n');
|
bufptr = strchr(bufptr, '\n');
|
||||||
}
|
}
|
||||||
return -1;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
||||||
@@ -332,14 +335,16 @@ int machine_get_loadavg(double *load)
|
|||||||
|
|
||||||
int machine_get_meminfo(meminfo_type *result)
|
int machine_get_meminfo(meminfo_type *result)
|
||||||
{
|
{
|
||||||
|
long tmp;
|
||||||
|
|
||||||
reread(meminfo_fd, "get_meminfo");
|
reread(meminfo_fd, "get_meminfo");
|
||||||
result[0].total = getentry("MemTotal:", procbuf);
|
result[0].total = (getentry("MemTotal:", procbuf, &tmp) == TRUE) ? tmp : 0L;
|
||||||
result[0].free = getentry("MemFree:", procbuf);
|
result[0].free = (getentry("MemFree:", procbuf, &tmp) == TRUE) ? tmp : 0L;
|
||||||
result[0].shared = getentry("MemShared:", procbuf);
|
result[0].shared = (getentry("MemShared:", procbuf, &tmp) == TRUE) ? tmp : 0L;
|
||||||
result[0].buffers = getentry("Buffers:", procbuf);
|
result[0].buffers = (getentry("Buffers:", procbuf, &tmp) == TRUE) ? tmp : 0L;
|
||||||
result[0].cache = getentry("Cached:", procbuf);
|
result[0].cache = (getentry("Cached:", procbuf, &tmp) == TRUE) ? tmp : 0L;
|
||||||
result[1].total = getentry("SwapTotal:", procbuf);
|
result[1].total = (getentry("SwapTotal:", procbuf, &tmp) == TRUE) ? tmp : 0L;
|
||||||
result[1].free = getentry("SwapFree:", procbuf);
|
result[1].free = (getentry("SwapFree:", procbuf, &tmp) == TRUE) ? tmp : 0L;
|
||||||
|
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user