]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
findfs: use getopt_long() to parse options
authorSami Kerola <kerolasa@iki.fi>
Mon, 17 Apr 2017 20:43:35 +0000 (21:43 +0100)
committerSami Kerola <kerolasa@iki.fi>
Tue, 2 May 2017 22:22:04 +0000 (23:22 +0100)
This change makes the findfs(8) more coherent with other commands in the
project source tree.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
misc-utils/findfs.c

index e260541a8bcccba90ddf13754e4fa646ce0dc1df..7935232eba4b8a879d580020eb6d08ad69974e77 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <getopt.h>
 
 #include <blkid.h>
 
@@ -41,6 +42,12 @@ static void __attribute__((__noreturn__)) usage(int rc)
 int main(int argc, char **argv)
 {
        char    *dev;
+       int     c;
+       static const struct option longopts[] = {
+               {"version", no_argument, NULL, 'V'},
+               {"help", no_argument, NULL, 'h'},
+               {NULL, 0, NULL, 0}
+       };
 
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
@@ -52,15 +59,16 @@ int main(int argc, char **argv)
                 * with version from e2fsprogs */
                usage(FINDFS_USAGE_ERROR);
 
-       if (strcmp(argv[1], "-V") == 0 ||
-                  strcmp(argv[1], "--version") == 0) {
-               printf(UTIL_LINUX_VERSION);
-               return FINDFS_SUCCESS;
-       } else if (strcmp(argv[1], "-h") == 0 ||
-                  strcmp(argv[1], "--help") == 0) {
-               usage(FINDFS_SUCCESS);
-       } else if (argv[1][0] == '-')
-               usage(FINDFS_USAGE_ERROR);
+       while ((c = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
+               switch (c) {
+               case 'V':
+                       printf(UTIL_LINUX_VERSION);
+                       return EXIT_SUCCESS;
+               case 'h':
+                       usage(FINDFS_SUCCESS);
+               default:
+                       errtryhelp(EXIT_FAILURE);
+               }
 
        dev = blkid_evaluate_tag(argv[1], NULL, NULL);
        if (!dev)