use long for meminfo_type elements

This commit is contained in:
marschap
2006-12-10 20:09:12 +00:00
parent 00b0136ec2
commit e765e19a0e
2 changed files with 26 additions and 21 deletions
+6 -6
View File
@@ -46,18 +46,18 @@ typedef struct
typedef struct
{
int total; /**< total memory (in kB) */
int cache; /**< memory in page cache (in kB) */
int buffers; /**< memory in buffer cache (in kB) */
int free; /**< free memory (in kB) */
int shared; /**< ??? (in kB) */
long total; /**< total memory (in kB) */
long cache; /**< memory in page cache (in kB) */
long buffers; /**< memory in buffer cache (in kB) */
long free; /**< free memory (in kB) */
long shared; /**< ??? (in kB) */
} meminfo_type;
typedef struct
{
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 */
} procinfo_type;
+20 -15
View File
@@ -153,26 +153,29 @@ reread (int f, char *errmsg)
exit(1);
}
long
getentry (const char *tag, const char *bufptr)
static int
getentry (const char *tag, const char *bufptr, long *value)
{
char *tail;
int len = strlen(tag);
long retval;
long val;
while (bufptr != NULL) {
if (*bufptr == '\n')
bufptr++;
if (!strncmp(tag, bufptr, len)) {
retval = strtol(bufptr + len, &tail, 10);
if (tail == bufptr + len)
return -1;
errno = 0;
val = strtol(bufptr + len, &tail, 10);
if ((errno == 0) && (tail != bufptr + len)) {
*value = val;
return TRUE;
}
else
return retval;
return FALSE;
}
bufptr = strchr(bufptr, '\n');
}
return -1;
return FALSE;
}
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)
{
long tmp;
reread(meminfo_fd, "get_meminfo");
result[0].total = getentry("MemTotal:", procbuf);
result[0].free = getentry("MemFree:", procbuf);
result[0].shared = getentry("MemShared:", procbuf);
result[0].buffers = getentry("Buffers:", procbuf);
result[0].cache = getentry("Cached:", procbuf);
result[1].total = getentry("SwapTotal:", procbuf);
result[1].free = getentry("SwapFree:", procbuf);
result[0].total = (getentry("MemTotal:", procbuf, &tmp) == TRUE) ? tmp : 0L;
result[0].free = (getentry("MemFree:", procbuf, &tmp) == TRUE) ? tmp : 0L;
result[0].shared = (getentry("MemShared:", procbuf, &tmp) == TRUE) ? tmp : 0L;
result[0].buffers = (getentry("Buffers:", procbuf, &tmp) == TRUE) ? tmp : 0L;
result[0].cache = (getentry("Cached:", procbuf, &tmp) == TRUE) ? tmp : 0L;
result[1].total = (getentry("SwapTotal:", procbuf, &tmp) == TRUE) ? tmp : 0L;
result[1].free = (getentry("SwapFree:", procbuf, &tmp) == TRUE) ? tmp : 0L;
return(TRUE);
}