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_key.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'c_src/cmd_key.c') diff --git a/c_src/cmd_key.c b/c_src/cmd_key.c index c1b72ff4..6cdf1d3f 100644 --- a/c_src/cmd_key.c +++ b/c_src/cmd_key.c @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -15,16 +16,23 @@ static void unlock_usage(void) "Usage: bcachefs unlock [OPTION] device\n" "\n" "Options:\n" - " -c Check if a device is encrypted\n" - " -k (session|user|user_session)\n" + " -c, --check Check if a device is encrypted\n" + " -k, --keyring (session|user|user_session)\n" " Keyring to add to (default: user)\n" - " -f Passphrase file to read from (disables passphrase prompt)\n" - " -h Display this help and exit\n" + " -f, --file Passphrase file to read from (disables passphrase prompt)\n" + " -h, --help Display this help and exit\n" "Report bugs to "); } int cmd_unlock(int argc, char *argv[]) { + static const struct option longopts[] = { + { "check", no_argument, NULL, 'c' }, + { "keyring", required_argument, NULL, 'k' }, + { "file", required_argument, NULL, 'f' }, + { "help", no_argument, NULL, 'h' }, + { NULL } + }; const char *keyring = "user"; bool check = false; const char *passphrase_file_path = NULL; @@ -32,7 +40,7 @@ int cmd_unlock(int argc, char *argv[]) int opt; - while ((opt = getopt(argc, argv, "cf:k:h")) != -1) + while ((opt = getopt_long(argc, argv, "cf:k:h", longopts, NULL)) != -1) switch (opt) { case 'c': check = true; -- cgit v1.2.3