+ state = sysctl_rslt;
+ if (state == 0 && batt_info->percentage_remaining == 100)
+ batt_info->status = CS_FULL;
+ else if ((state & ACPI_BATT_STAT_CHARGING) && batt_info->percentage_remaining < 100)
+ batt_info->status = CS_CHARGING;
+ else
+ batt_info->status = CS_DISCHARGING;
+#elif defined(__OpenBSD__)
+ /*
+ * We're using apm(4) here, which is the interface to acpi(4) on amd64/i386 and
+ * the generic interface on macppc/sparc64/zaurus, instead of using sysctl(3) and
+ * probing acpi(4) devices.
+ */
+ struct apm_power_info apm_info;
+ int apm_fd;
+
+ apm_fd = open("/dev/apm", O_RDONLY);
+ if (apm_fd < 0) {
+ OUTPUT_FULL_TEXT("can't open /dev/apm");
+ return false;
+ }
+ if (ioctl(apm_fd, APM_IOC_GETPOWER, &apm_info) < 0)
+ OUTPUT_FULL_TEXT("can't read power info");
+
+ close(apm_fd);
+
+ /* Don't bother to go further if there's no battery present. */
+ if ((apm_info.battery_state == APM_BATTERY_ABSENT) ||
+ (apm_info.battery_state == APM_BATT_UNKNOWN)) {
+ OUTPUT_FULL_TEXT(format_down);
+ return false;
+ }
+
+ switch (apm_info.ac_state) {
+ case APM_AC_OFF:
+ batt_info->status = CS_DISCHARGING;
+ break;
+ case APM_AC_ON:
+ batt_info->status = CS_CHARGING;
+ break;
+ default:
+ /* If we don't know what's going on, just assume we're discharging. */
+ batt_info->status = CS_DISCHARGING;
+ break;
+ }
+
+ batt_info->percentage_remaining = apm_info.battery_life;
+
+ /* Can't give a meaningful value for remaining minutes if we're charging. */
+ if (batt_info->status != CS_CHARGING) {
+ batt_info->seconds_remaining = apm_info.minutes_left * 60;
+ }
+#elif defined(__NetBSD__)
+ /*
+ * Using envsys(4) via sysmon(4).
+ */
+ bool watt_as_unit = false;
+ int full_design = -1,
+ remaining = -1,
+ voltage = -1;
+ int fd, rval, last_full_cap;
+ bool is_found = false;
+ char *sensor_desc;
+ bool is_full = false;
+
+ prop_dictionary_t dict;
+ prop_array_t array;
+ prop_object_iterator_t iter;
+ prop_object_iterator_t iter2;
+ prop_object_t obj, obj2, obj3, obj4, obj5;
+
+ asprintf(&sensor_desc, "acpibat%d", number);
+
+ fd = open("/dev/sysmon", O_RDONLY);
+ if (fd < 0) {
+ OUTPUT_FULL_TEXT("can't open /dev/sysmon");
+ return false;
+ }
+
+ rval = prop_dictionary_recv_ioctl(fd, ENVSYS_GETDICTIONARY, &dict);
+ if (rval == -1) {
+ close(fd);
+ return false;
+ }
+
+ if (prop_dictionary_count(dict) == 0) {
+ prop_object_release(dict);
+ close(fd);
+ return false;
+ }
+
+ iter = prop_dictionary_iterator(dict);
+ if (iter == NULL) {
+ prop_object_release(dict);
+ close(fd);
+ }
+
+ /* iterate over the dictionary returned by the kernel */
+ while ((obj = prop_object_iterator_next(iter)) != NULL) {
+ /* skip this dict if it's not what we're looking for */
+ if (strcmp(sensor_desc,
+ prop_dictionary_keysym_cstring_nocopy(obj)) != 0)
+ continue;
+
+ is_found = true;
+
+ array = prop_dictionary_get_keysym(dict, obj);
+ if (prop_object_type(array) != PROP_TYPE_ARRAY) {
+ prop_object_iterator_release(iter);
+ prop_object_release(dict);
+ close(fd);
+ return false;