+ while (fgets (buffer, sizeof (buffer), fh) != NULL)
+ {
+ char *fields[8];
+ int numfields;
+
+ numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
+ if (numfields < 2)
+ continue;
+
+ if (strcasecmp (fields[0], "SwapTotal:") == 0)
+ {
+ swap_total = strtod (fields[1], /* endptr = */ NULL);
+ have_data |= 0x01;
+ }
+ else if (strcasecmp (fields[0], "SwapFree:") == 0)
+ {
+ swap_free = strtod (fields[1], /* endptr = */ NULL);
+ have_data |= 0x02;
+ }
+ else if (strcasecmp (fields[0], "SwapCached:") == 0)
+ {
+ swap_cached = strtod (fields[1], /* endptr = */ NULL);
+ have_data |= 0x04;
+ }
+ }
+
+ fclose (fh);
+
+ if (have_data != 0x07)
+ return (ENOENT);
+
+ if (isnan (swap_total)
+ || (swap_total <= 0.0)
+ || ((swap_free + swap_cached) > swap_total))
+ return (EINVAL);