+static int read_acpi_full_capacity (char const *dir, /* {{{ */
+ char const *power_supply,
+ gauge_t *ret_capacity)
+{
+ char filename[PATH_MAX];
+ char buffer[1024];
+
+ FILE *fh;
+
+ ssnprintf (filename, sizeof (filename), "%s/%s/info", dir, power_supply);
+ fh = fopen (filename, "r");
+ if ((fh = fopen (filename, "r")) == NULL)
+ return (errno);
+
+ /* last full capacity: 40090 mWh */
+ while (fgets (buffer, sizeof (buffer), fh) != NULL)
+ {
+ char *fields[8];
+ int numfields;
+ int status;
+
+ if (strncmp ("last full capacity:", buffer, strlen ("last full capacity:")) != 0)
+ continue;
+
+ numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
+ if (numfields < 5)
+ continue;
+
+ status = strtogauge (fields[3], ret_capacity);
+ fclose (fh);
+ return (status);
+ }
+
+ fclose (fh);
+ return (ENOENT);
+} /* }}} int read_acpi_full_capacity */
+