summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2bdaa47)
raw | patch | inline | side by side (parent: 2bdaa47)
author | Florian Forster <octo@noris.net> | |
Wed, 9 Jun 2010 11:10:18 +0000 (13:10 +0200) | ||
committer | Florian Forster <octo@noris.net> | |
Wed, 16 Jun 2010 13:38:04 +0000 (15:38 +0200) |
src/swap.c | patch | blob | history |
diff --git a/src/swap.c b/src/swap.c
index e467818db4ca01f65af8fd66eb0c7780d571fec3..68a5b71c84cfbbfee5e7a746115417c6ffc44a0e 100644 (file)
--- a/src/swap.c
+++ b/src/swap.c
return (-1);
}
- while (fgets (buffer, 1024, fh) != NULL)
+ while (fgets (buffer, sizeof (buffer), fh) != NULL)
{
- derive_t *val = NULL;
-
- if (strncasecmp (buffer, "SwapTotal:", 10) == 0)
- val = &swap_total;
- else if (strncasecmp (buffer, "SwapFree:", 9) == 0)
- val = &swap_free;
- else if (strncasecmp (buffer, "SwapCached:", 11) == 0)
- val = &swap_cached;
- else
- continue;
-
- numfields = strsplit (buffer, fields, 8);
-
+ numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
if (numfields < 2)
continue;
- *val = (derive_t) atoll (fields[1]) * 1024LL;
+ if (strcasecmp (fields[0], "SwapTotal:") == 0)
+ strtoderive (fields[1], &swap_total);
+ else if (strcasecmp (fields[0], "SwapFree:") == 0)
+ strtoderive (fields[1], &swap_free);
+ else if (strcasecmp (fields[0], "SwapCached:") == 0)
+ strtoderive (fields[1], &swap_cached);
}
if (fclose (fh))
old_kernel = 1;
}
- while (fgets (buffer, 1024, fh) != NULL)
+ while (fgets (buffer, sizeof (buffer), fh) != NULL)
{
numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));