From a722d110d876b97ec87e7616a93f3e990e928bbf Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Wed, 25 Dec 2013 23:17:28 -0800 Subject: [PATCH] Parse options with getopt instead of strcmp --- keystroke-timestamps.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/keystroke-timestamps.c b/keystroke-timestamps.c index 6e3de63..2ab4c42 100644 --- a/keystroke-timestamps.c +++ b/keystroke-timestamps.c @@ -1,14 +1,26 @@ #include #include +#include #include #include +#include #include #include #include int main (int argc, char **argv) { - int print_usec = argc > 1 && strcmp(argv[1], "--usec") == 0; + int print_usec = 0; + struct option long_options[] = { + {"usec", no_argument, &print_usec, 1 }, + {0, 0, 0, 0 }, + }; + while (1) { + int c = getopt_long(argc, argv, "", long_options, NULL); + if (c == -1) break; + if (c != 0) exit(EX_USAGE); + } + int fd = open("/dev/input/by-path/platform-i8042-serio-0-event-kbd", O_RDONLY); if (fd < 0) { err(EX_NOINPUT, "Could not open keyboard event file"); -- 2.51.2