blob: 0b5b4a15792903bfc7c690d72fb293d7c4c846a7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <stdint.h>
#include <err.h>
#include <sys/mman.h>
#define LEN 5
int fd;
char buf[LEN];
struct stat sb;
void *ptr;
int main()
{
buf[LEN - 1] = '\n';
fd = open("/sys/class/power_supply/macsmc-battery/capacity", O_RDONLY);
read(fd, buf, LEN);
printf("%s", buf);
ptr = mmap(NULL, LEN, PROT_READ, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
perror("mmap");
_exit(0);
}
for (;;) {
dprintf(1, "%p\n", ptr);
// There's gotta be a better way to do this than polling the battery
// file. I could use dbus to contact upower but I'm unfamiliar with
// dbus interrupts.
// Note that inotify won't work with /sys/class files.
// And I'm not in the mood of handling errors today.
}
}
|