+ return 0;
+ }
+ return close(fd), 1;
+ }
+
+ const char *
+ battery_perc(const char *unused)
+ {
+ struct apm_power_info apm_info;
+
+ if (load_apm_power_info(&apm_info)) {
+ return bprintf("%d", apm_info.battery_life);
+ }
+
+ return NULL;
+ }
+
+ const char *
+ battery_state(const char *unused)
+ {
+ struct apm_power_info apm_info;
+ size_t i;
+ struct {
+ unsigned int state;
+ char *symbol;
+ } map[] = {
+ { APM_AC_ON, "+" },
+ { APM_AC_OFF, "-" },
+ };
+
+ if (load_apm_power_info(&apm_info)) {
+ for (i = 0; i < LEN(map); i++) {
+ if (map[i].state == apm_info.ac_state) {
+ break;
+ }
+ }
+ return (i == LEN(map)) ? "?" : map[i].symbol;
+ }
+
+ return NULL;
+ }
+
+ const char *
+ battery_remaining(const char *unused)
+ {
+ struct apm_power_info apm_info;
+
+ if (load_apm_power_info(&apm_info)) {
+ return bprintf("%u:%02u", apm_info.minutes_left / 60,
+ apm_info.minutes_left % 60);