+#elif defined(__OpenBSD__)
+ struct apm_power_info apm_info;
+ int fd;
+
+ fd = open("/dev/apm", O_RDONLY);
+ if (fd < 0) {
+ warn("Failed to open file /dev/apm");
+ return NULL;
+ }
+
+ if (ioctl(fd, APM_IOC_GETPOWER, &apm_info) < 0) {
+ warn("Failed to get battery info");
+ close(fd);
+ return NULL;
+ }
+ close(fd);
+
+ return bprintf("%d", apm_info.battery_life);
+#endif