]> git.scottworley.com Git - keystroke-timestamps/blobdiff - keystroke-timestamps.c
Add proper error reporting for open failures
[keystroke-timestamps] / keystroke-timestamps.c
index 670b43c73c9b7aa2eee530861105dc41311d9a46..5322e6bff1b5682698a72d30c4f92012912c88d9 100644 (file)
@@ -2,12 +2,17 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <linux/input.h>
+#include <err.h>
+#include <sysexits.h>
 
 int main ()
 {
   struct input_event i;
   int fd = open("/dev/input/by-path/platform-i8042-serio-0-event-kbd", O_RDONLY);
-  while (fd && read(fd, &i, sizeof(i)) == sizeof(i)) {
+  if (fd < 0) {
+    err(EX_NOINPUT, "Could not open keyboard event file");
+  }
+  while (read(fd, &i, sizeof(i)) == sizeof(i)) {
     if (i.type == 1 && i.value == 1) {
       printf("%ld.%ld\n", i.time.tv_sec, i.time.tv_usec);
       fflush(stdout);