1 /* write battery/thermal status to a file ... */
8 #include <sys/select.h>
11 #define BATFILE "/proc/acpi/battery/BAT0/state"
13 int main(int argc,char **argv) {
24 puts("file to read bat status from not specified,");
25 printf("using %s.\n",BATFILE);
26 strcpy(batfile,BATFILE);
29 printf("using %s ...\n",argv[1]);
30 strncpy(batfile,argv[1],64-1);
33 if((batfd=open(batfile,O_RDONLY))<0) {
34 printf("unable to open file %s\n",batfile);
38 if((msgfd=open("/var/log/battery",O_WRONLY))<0) {
39 puts("unable to open file /var/log/battery");
47 if(select(1,NULL,NULL,NULL,&to)<0) {
48 puts("select call failed");
52 i=read(batfd,buf,512);
53 lseek(batfd,0,SEEK_SET);
55 if(strncmp(buf_o,buf,i)) {
56 dprintf(msgfd,"%s",buf);