From e7cc6bb9cfd0d5de310d5eb61fd17693a2b4d60b Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Fri, 4 Jul 2025 12:34:24 -0400 Subject: getopt() -> getopt_long() Kill all remaining getopt() uses - all options can now be passed as longopts. Signed-off-by: Kent Overstreet --- c_src/cmd_data.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'c_src/cmd_data.c') diff --git a/c_src/cmd_data.c b/c_src/cmd_data.c index 5a1a1485..70d945a6 100644 --- a/c_src/cmd_data.c +++ b/c_src/cmd_data.c @@ -26,9 +26,13 @@ static void data_rereplicate_usage(void) static int cmd_data_rereplicate(int argc, char *argv[]) { + static const struct option longopts[] = { + { "help", 0, NULL, 'h' }, + { NULL } + }; int opt; - while ((opt = getopt(argc, argv, "h")) != -1) + while ((opt = getopt_long(argc, argv, "h", longopts, NULL)) != -1) switch (opt) { case 'h': data_rereplicate_usage(); @@ -262,16 +266,23 @@ static void data_job_usage(void) "job: one of scrub, rereplicate, migrate, rewrite_old_nodes, or drop_extra_replicas\n" "\n" "Options:\n" - " -b btree btree to operate on\n" - " -s inode:offset start position\n" - " -e inode:offset end position\n" - " -h, --help display this help and exit\n" + " -b, --btree btree btree to operate on\n" + " -s, --start inode:offset start position\n" + " -e, --end inode:offset end position\n" + " -h, --help display this help and exit\n" "Report bugs to "); exit(EXIT_SUCCESS); } static int cmd_data_job(int argc, char *argv[]) { + static const struct option longopts[] = { + { "btree", required_argument, NULL, 'b' }, + { "start", required_argument, NULL, 's' }, + { "end", required_argument, NULL, 'e' }, + { "help", no_argument, NULL, 'h' }, + { NULL } + }; struct bch_ioctl_data op = { .start_btree = 0, .start_pos = POS_MIN, @@ -280,7 +291,7 @@ static int cmd_data_job(int argc, char *argv[]) }; int opt; - while ((opt = getopt(argc, argv, "s:e:h")) != -1) + while ((opt = getopt_long(argc, argv, "b:s:e:h", longopts, NULL)) != -1) switch (opt) { case 'b': op.start_btree = read_string_list_or_die(optarg, @@ -290,8 +301,8 @@ static int cmd_data_job(int argc, char *argv[]) case 's': op.start_pos = bpos_parse(optarg); break; - op.end_pos = bpos_parse(optarg); case 'e': + op.end_pos = bpos_parse(optarg); break; case 'h': data_job_usage(); -- cgit v1.2.3