[PATCH 09/10] findfs: use getopt_long() to parse options

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This change makes the findfs(8) more coherent with other commands in the
project source tree.

Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 misc-utils/findfs.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/misc-utils/findfs.c b/misc-utils/findfs.c
index e260541a8..cb69323aa 100644
--- a/misc-utils/findfs.c
+++ b/misc-utils/findfs.c
@@ -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:
+			usage(FINDFS_USAGE_ERROR);
+		}
 
 	dev = blkid_evaluate_tag(argv[1], NULL, NULL);
 	if (!dev)
-- 
2.12.2

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux