From: Scott Worley Date: Wed, 4 Sep 2013 18:04:58 +0000 (-0700) Subject: Add proper error reporting for open failures X-Git-Tag: v1.0.0~17 X-Git-Url: http://git.scottworley.com/keystroke-timestamps/commitdiff_plain/a9258ceda1c9a550750a9af8a99130cf6b87c474?hp=--cc Add proper error reporting for open failures --- a9258ceda1c9a550750a9af8a99130cf6b87c474 diff --git a/keystroke-timestamps.c b/keystroke-timestamps.c index 670b43c..5322e6b 100644 --- a/keystroke-timestamps.c +++ b/keystroke-timestamps.c @@ -2,12 +2,17 @@ #include #include #include +#include +#include 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);