summaryrefslogtreecommitdiff
path: root/src/udev
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-03-13 11:46:01 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-03-16 16:46:44 +0100
commit8b89b9d7c324953ac8c09e2f04f47246e39aa6cf (patch)
tree96204df81ba63199db64673dfae2d0a8cf546482 /src/udev
parent4b0f96748411a1bef8bdc0bae6f9e9d316223028 (diff)
downloadsystemd-8b89b9d7c324953ac8c09e2f04f47246e39aa6cf.tar.gz
udev/mtd_probe: implement --help
Diffstat (limited to 'src/udev')
-rw-r--r--src/udev/mtd_probe/mtd_probe.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/udev/mtd_probe/mtd_probe.c b/src/udev/mtd_probe/mtd_probe.c
index a7210a05e3..fd6267feb5 100644
--- a/src/udev/mtd_probe/mtd_probe.c
+++ b/src/udev/mtd_probe/mtd_probe.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <getopt.h>
#include <mtd/mtd-user.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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) {