diff options
author | David Sterba <dsterba@suse.com> | 2016-03-01 16:02:08 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-03-14 13:42:47 +0100 |
commit | babe94e4817aca45aef409b7a21bc47e51cda6ff (patch) | |
tree | a00641b956754d6bd002bb23c6b8e3d3a18b8740 /cmds-inspect.c | |
parent | c27640938de1506e0a02f7f928a00886d5da616a (diff) |
btrfs-progs: add getopt stubs where needed
Commands that do not take any options do not use getopt, which means the
standard option separator "--" does not work. Update all command
handlers that need it, argv needs to be referenced using the optind that
is correctly pointed after the separator.
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-inspect.c')
-rw-r--r-- | cmds-inspect.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/cmds-inspect.c b/cmds-inspect.c index 176f8360..dbc6656d 100644 --- a/cmds-inspect.c +++ b/cmds-inspect.c @@ -268,22 +268,24 @@ static int cmd_inspect_subvolid_resolve(int argc, char **argv) char path[PATH_MAX]; DIR *dirstream = NULL; - if (check_argc_exact(argc, 3)) + clean_args_no_options(argc, argv, cmd_inspect_subvolid_resolve_usage); + + if (check_argc_exact(argc - optind, 2)) usage(cmd_inspect_subvolid_resolve_usage); - fd = btrfs_open_dir(argv[2], &dirstream, 1); + fd = btrfs_open_dir(argv[optind], &dirstream, 1); if (fd < 0) { ret = -ENOENT; goto out; } - subvol_id = arg_strtou64(argv[1]); + subvol_id = arg_strtou64(argv[optind]); ret = btrfs_subvolid_resolve(fd, path, sizeof(path), subvol_id); if (ret) { fprintf(stderr, - "%s: btrfs_subvolid_resolve(subvol_id %llu) failed with ret=%d\n", - argv[0], (unsigned long long)subvol_id, ret); + "btrfs_subvolid_resolve(subvol_id %llu) failed with ret=%d\n", + (unsigned long long)subvol_id, ret); goto out; } @@ -308,10 +310,12 @@ static int cmd_inspect_rootid(int argc, char **argv) u64 rootid; DIR *dirstream = NULL; - if (check_argc_exact(argc, 2)) + clean_args_no_options(argc, argv, cmd_inspect_rootid_usage); + + if (check_argc_exact(argc - optind, 1)) usage(cmd_inspect_rootid_usage); - fd = btrfs_open_dir(argv[1], &dirstream, 1); + fd = btrfs_open_dir(argv[optind], &dirstream, 1); if (fd < 0) { ret = -ENOENT; goto out; @@ -319,8 +323,7 @@ static int cmd_inspect_rootid(int argc, char **argv) ret = lookup_ino_rootid(fd, &rootid); if (ret) { - fprintf(stderr, "%s: rootid failed with ret=%d\n", - argv[0], ret); + fprintf(stderr, "rootid failed with ret=%d\n", ret); goto out; } |