From: Zbigniew Jędrzejewski-Szmek Date: Mon, 13 Mar 2023 10:46:01 +0000 (+0100) Subject: udev/mtd_probe: implement --help X-Git-Tag: v254-rc1~936^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8b89b9d7c324953ac8c09e2f04f47246e39aa6cf;p=thirdparty%2Fsystemd.git udev/mtd_probe: implement --help --- diff --git a/src/udev/mtd_probe/mtd_probe.c b/src/udev/mtd_probe/mtd_probe.c index a7210a05e3c..fd6267feb50 100644 --- a/src/udev/mtd_probe/mtd_probe.c +++ b/src/udev/mtd_probe/mtd_probe.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -32,14 +33,43 @@ #include "fd-util.h" #include "mtd_probe.h" +static const char *arg_device = NULL; + +static int parse_argv(int argc, char *argv[]) { + static const struct option options[] = { + { "help", no_argument, NULL, 'h' }, + {} + }; + int c; + + while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) + switch (c) { + case 'h': + printf("%s /dev/mtd[n]\n\n" + " -h --help Show this help text\n", + program_invocation_short_name); + return 0; + case '?': + return -EINVAL; + default: + assert_not_reached(); + } + + if (argc > 2) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Error: unexpected argument."); + + arg_device = argv[optind]; + return 1; +} + int main(int argc, char** argv) { _cleanup_close_ int mtd_fd = -EBADF; mtd_info_t mtd_info; + int r; - if (argc != 2) { - printf("usage: mtd_probe /dev/mtd[n]\n"); - return EXIT_FAILURE; - } + r = parse_argv(argc, argv); + if (r <= 0) + return r < 0 ? EXIT_FAILURE : 0; mtd_fd = open(argv[1], O_RDONLY|O_CLOEXEC|O_NOCTTY); if (mtd_fd < 0) {