From 49c3a5c79c83695ee603c9d2b890d68cfe7b9619 Mon Sep 17 00:00:00 2001
From: hackbard <hackbard>
Date: Wed, 18 Aug 2004 09:06:40 +0000
Subject: [PATCH 1/1] initial checkin - doesnt work by now!

---
 print_info.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100644 print_info.c

diff --git a/print_info.c b/print_info.c
new file mode 100644
index 0000000..8e7ce80
--- /dev/null
+++ b/print_info.c
@@ -0,0 +1,62 @@
+/* write battery/thermal status to a file ... */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/select.h>
+#include <unistd.h>
+
+#define BATFILE "/proc/acpi/battery/BAT0/state"
+
+int main(int argc,char **argv) {
+
+	int msgfd;
+	int batfd;
+	char batfile[64];
+	struct timeval to;
+	char buf[512];
+	char buf_o[512];
+	int i;
+
+	if(argc<2) {
+		puts("file to read bat status from not specified,");
+		printf("using %s.\n",BATFILE);
+		strcpy(batfile,BATFILE);
+	}
+	else {
+		printf("using %s ...\n",argv[1]);
+		strncpy(batfile,argv[1],64-1);
+	}
+
+	if((batfd=open(batfile,O_RDONLY))<0) {
+		printf("unable to open file %s\n",batfile);
+		return -1;
+	}
+
+	if((msgfd=open("/var/log/battery",O_WRONLY))<0) {
+		puts("unable to open file /var/log/battery");
+		return -1;
+	}
+
+	to.tv_sec=2;
+	to.tv_usec=0;
+
+	while(1) {
+		if(select(1,NULL,NULL,NULL,&to)<0) {
+			puts("select call failed");
+			return -1;
+		}
+
+		i=read(batfd,buf,512);
+		lseek(batfd,0,SEEK_SET);
+		buf[i]='\0';
+		if(strncmp(buf_o,buf,i)) {
+			dprintf(msgfd,"%s",buf);
+			strcpy(buf_o,buf);
+		}
+	}
+
+	return 1;
+}
-- 
2.39.5