From 4647ab887a592516841f74fa47586771bbcad81b Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 11 Jun 2015 00:04:19 +0200 Subject: btrfs-progs: accept --help as option in the standalone utilities Signed-off-by: David Sterba --- btrfs-find-root.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'btrfs-find-root.c') diff --git a/btrfs-find-root.c b/btrfs-find-root.c index 9e56c81..1cb3085 100644 --- a/btrfs-find-root.c +++ b/btrfs-find-root.c @@ -22,6 +22,8 @@ #include #include #include +#include + #include "kerncompat.h" #include "ctree.h" #include "disk-io.h" @@ -142,15 +144,23 @@ int main(int argc, char **argv) struct btrfs_find_root_filter filter = {0}; struct cache_tree result; struct cache_extent *found; - int opt; int ret; /* Default to search root tree */ filter.objectid = BTRFS_ROOT_TREE_OBJECTID; filter.match_gen = (u64)-1; filter.match_level = (u8)-1; - while ((opt = getopt(argc, argv, "al:o:g:")) != -1) { - switch(opt) { + while (1) { + static const struct option long_options[] = { + { "help", no_argument, NULL, GETOPT_VAL_HELP}, + { NULL, 0, NULL, 0 } + }; + int c = getopt_long(argc, argv, "al:o:g:", long_options, NULL); + + if (c < 0) + break; + + switch (c) { case 'a': filter.search_all = 1; break; @@ -163,9 +173,10 @@ int main(int argc, char **argv) case 'l': filter.level = arg_strtou64(optarg); break; + case GETOPT_VAL_HELP: default: usage(); - exit(1); + exit(c != GETOPT_VAL_HELP); } } -- cgit v1.2.1