grtcdr Assuming you don't want to link against the proplib
library, you can just issue the ioctl
, retrieve the XML dictionary plist, then parse the XML in whatever language you want to get battery stats.
The following program just dumps the XML retrieved from the kernel:
/**
* Print the global property dictionary (XML) on NetBSD.
*/
#include <sys/types.h>
#include <sys/envsys.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <prop/plistref.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int
main(void)
{
struct plistref P;
int fd, rc = EXIT_FAILURE;
char* dev = "/dev/sysmon";
if ((fd = open(dev, O_RDONLY)) == -1)
err(rc, "%s: open failed.", dev);
if (ioctl(fd, ENVSYS_GETDICTIONARY, &P) == -1)
err(rc, "%s: ioctl failed.", dev);
/*
* ripped from:
* src/common/lib/libprop/prop_kern.c
*/
if (P.pref_len == 0)
errx(rc, "pref_len == 0");
printf("%.*s", (int)P.pref_len, (char* )P.pref_plist);
munmap(P.pref_plist, P.pref_len);
close(fd);
return 0;
}