From 6a3935d457e6984236b32d98af889d78684163cc Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 9 Jun 2010 13:10:18 +0200 Subject: [PATCH] swap plugin: Use "strtoderive" to parse strings. --- src/swap.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/swap.c b/src/swap.c index e467818d..68a5b71c 100644 --- a/src/swap.c +++ b/src/swap.c @@ -210,25 +210,18 @@ static int swap_read (void) 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)) @@ -257,7 +250,7 @@ static int swap_read (void) old_kernel = 1; } - while (fgets (buffer, 1024, fh) != NULL) + while (fgets (buffer, sizeof (buffer), fh) != NULL) { numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields)); -- 2.30.2