diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2025-07-04 12:34:24 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2025-07-04 12:47:30 -0400 |
commit | e7cc6bb9cfd0d5de310d5eb61fd17693a2b4d60b (patch) | |
tree | 71c4c24abd6cfed054555c0de906827fe5266d8e /c_src/cmd_data.c | |
parent | 7d69a303d1c5eafd860c2377a013fd2aaad43ba2 (diff) |
getopt() -> getopt_long()
Kill all remaining getopt() uses - all options can now be passed as
longopts.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'c_src/cmd_data.c')
-rw-r--r-- | c_src/cmd_data.c | 25 |
1 files changed, 18 insertions, 7 deletions
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 <linux-bcachefs@vger.kernel.org>"); 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(); |