I personally think it would be better to use getopt() here.

Regards

-- 
Iain Bucław

*(p < e ? p++ : p) = (c & 0x0f) + '0';
diff -Naurp btrfs-tools-0.19.orig/btrfsck.c btrfs-tools-0.19/btrfsck.c
--- btrfs-tools-0.19.orig/btrfsck.c	2009-06-11 17:56:15.000000000 +0100
+++ btrfs-tools-0.19/btrfsck.c	2010-02-14 20:53:21.000000000 +0000
@@ -21,6 +21,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
+#include <getopt.h>
 #include "kerncompat.h"
 #include "ctree.h"
 #include "disk-io.h"
@@ -2441,16 +2442,38 @@ static void print_usage(void)
 	exit(1);
 }
 
+static char *btrfs_parseopts(int ac, char **av)
+{
+        int c;
+
+        if (ac < 2)
+                print_usage();
+
+	while ((c = getopt (ac, av, "apy")) != EOF)
+	
+		switch (c) {
+		case 'a':
+		case 'p':
+		case 'y':
+		default:
+			break;
+		}
+	if (optind != ac - 1)
+                print_usage();
+
+	return (av[optind]);
+}
+
 int main(int ac, char **av)
 {
 	struct btrfs_root *root;
+	char *file;
 	int ret;
 
-	if (ac < 2)
-		print_usage();
+	file = btrfs_parseopts(ac, av);
 
 	radix_tree_init();
-	root = open_ctree(av[1], 0, 0);
+	root = open_ctree(file, 0, 0);
 
 	if (root == NULL)
 		return 1;

Reply via email to