]> git.scottworley.com Git - keystroke-timestamps/blobdiff - keystroke-timestamps.c
Sort includes
[keystroke-timestamps] / keystroke-timestamps.c
index 670b43c73c9b7aa2eee530861105dc41311d9a46..7c82a65f16e2743fd0ddf02b538c6bff5194c141 100644 (file)
@@ -1,13 +1,18 @@
+#include <err.h>
 #include <fcntl.h>
+#include <linux/input.h>
 #include <stdio.h>
+#include <sysexits.h>
 #include <unistd.h>
-#include <linux/input.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);