+ #include <unistd.h>
+
+ #define CHARGE_NOW "/sys/class/power_supply/%s/charge_now"
+ #define ENERGY_NOW "/sys/class/power_supply/%s/energy_now"
+ #define CURRENT_NOW "/sys/class/power_supply/%s/current_now"
+ #define POWER_NOW "/sys/class/power_supply/%s/power_now"
+
+ static const char *
+ pick(const char *bat, const char *f1, const char *f2, char *path,
+ size_t length)
+ {
+ if (esnprintf(path, length, f1, bat) > 0 &&
+ access(path, R_OK) == 0) {
+ return f1;
+ }
+
+ if (esnprintf(path, length, f2, bat) > 0 &&
+ access(path, R_OK) == 0) {
+ return f2;
+ }
+
+ return NULL;
+ }