static char *
swap_free(void)
{
- long free;
+ long total, free;
FILE *fp;
char buf[2048];
size_t bytes_read;
return smprintf(UNKNOWN_STR);
}
+ match = strstr(buf, "SwapTotal");
+ sscanf(match, "SwapTotal: %ld kB\n", &total);
+ if (total == 0) {
+ return smprintf(UNKNOWN_STR);
+ }
+
match = strstr(buf, "SwapFree");
sscanf(match, "SwapFree: %ld kB\n", &free);
return smprintf(UNKNOWN_STR);
}
- match = strstr(buf, "SwapCached");
- sscanf(match, "SwapCached: %ld kB\n", &cached);
-
match = strstr(buf, "SwapTotal");
sscanf(match, "SwapTotal: %ld kB\n", &total);
+ if (total == 0) {
+ return smprintf(UNKNOWN_STR);
+ }
+
+ match = strstr(buf, "SwapCached");
+ sscanf(match, "SwapCached: %ld kB\n", &cached);
match = strstr(buf, "SwapFree");
sscanf(match, "SwapFree: %ld kB\n", &free);
match = strstr(buf, "SwapTotal");
sscanf(match, "SwapTotal: %ld kB\n", &total);
+ if (total == 0) {
+ return smprintf(UNKNOWN_STR);
+ }
return smprintf("%f", (float)total / 1024 / 1024);
}
return smprintf(UNKNOWN_STR);
}
- match = strstr(buf, "SwapCached");
- sscanf(match, "SwapCached: %ld kB\n", &cached);
-
match = strstr(buf, "SwapTotal");
sscanf(match, "SwapTotal: %ld kB\n", &total);
+ if (total == 0) {
+ return smprintf(UNKNOWN_STR);
+ }
+
+ match = strstr(buf, "SwapCached");
+ sscanf(match, "SwapCached: %ld kB\n", &cached);
match = strstr(buf, "SwapFree");
sscanf(match, "SwapFree: %ld kB\n", &free);