Xinqi Bao's Git

Add warn() and die()
[slstatus.git] / components / battery.c
index 49f43e6..807a7e6 100644 (file)
 
                fd = open("/dev/apm", O_RDONLY);
                if (fd < 0) {
 
                fd = open("/dev/apm", O_RDONLY);
                if (fd < 0) {
-                       fprintf(stderr, "open '/dev/apm': %s\n", strerror(errno));
+                       warn("open '/dev/apm':");
                        return NULL;
                }
 
                if (ioctl(fd, APM_IOC_GETPOWER, &apm_info) < 0) {
                        return NULL;
                }
 
                if (ioctl(fd, APM_IOC_GETPOWER, &apm_info) < 0) {
-                       fprintf(stderr, "ioctl 'APM_IOC_GETPOWER': %s\n",
-                               strerror(errno));
+                       warn("ioctl 'APM_IOC_GETPOWER':");
                        close(fd);
                        return NULL;
                }
                        close(fd);
                        return NULL;
                }
 
                fd = open("/dev/apm", O_RDONLY);
                if (fd < 0) {
 
                fd = open("/dev/apm", O_RDONLY);
                if (fd < 0) {
-                       fprintf(stderr, "open '/dev/apm': %s\n", strerror(errno));
+                       warn("open '/dev/apm':");
                        return NULL;
                }
 
                if (ioctl(fd, APM_IOC_GETPOWER, &apm_info) < 0) {
                        return NULL;
                }
 
                if (ioctl(fd, APM_IOC_GETPOWER, &apm_info) < 0) {
-                       fprintf(stderr, "ioctl 'APM_IOC_GETPOWER': %s\n",
-                               strerror(errno));
+                       warn("ioctl 'APM_IOC_GETPOWER':");
                        close(fd);
                        return NULL;
                }
                        close(fd);
                        return NULL;
                }