diff options
author | Brian Norris <computersforpeace@gmail.com> | 2015-08-27 11:00:31 -0700 |
---|---|---|
committer | Brian Norris <computersforpeace@gmail.com> | 2015-11-11 14:05:36 -0800 |
commit | 9e2346121dd0745a444d719a33bf0774b72343b4 (patch) | |
tree | 402f70c8af95dd21d87066d370c962f1b0e92962 /flash_unlock.c | |
parent | 075fadd04e3ba4686b9beefb08d50be3242e02bb (diff) |
flash_{un,}lock: switch to getopt library
We will be adding some more flags, so the getopt library can help.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Diffstat (limited to 'flash_unlock.c')
-rw-r--r-- | flash_unlock.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/flash_unlock.c b/flash_unlock.c index ee8ac89..777e437 100644 --- a/flash_unlock.c +++ b/flash_unlock.c @@ -13,6 +13,7 @@ #define FLASH_UNLOCK 0 #endif +#include <getopt.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> @@ -35,6 +36,12 @@ static void usage(int status) exit(status); } +static const char short_opts[] = "h"; +static const struct option long_opts[] = { + { "help", no_argument, 0, 'h' }, + { NULL, 0, 0, 0 }, +}; + int main(int argc, char *argv[]) { int fd, request; @@ -43,11 +50,26 @@ int main(int argc, char *argv[]) int count; const char *dev; + for (;;) { + int c; + + c = getopt_long(argc, argv, short_opts, long_opts, NULL); + if (c == EOF) + break; + + switch (c) { + case 'h': + usage(0); + break; + default: + usage(1); + break; + } + } + /* Parse command line options */ if (argc < 2 || argc > 4) usage(1); - if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) - usage(0); dev = argv[1]; |