From 933e118f7b5e6c0e8bfb408f95f53dcc711f2beb Mon Sep 17 00:00:00 2001 From: Integral Date: Sat, 5 Oct 2024 21:16:03 +0800 Subject: [PATCH 1/2] apfs-label: add long option --version --- apfs-label/apfs-label.8 | 2 +- apfs-label/apfs-label.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/apfs-label/apfs-label.8 b/apfs-label/apfs-label.8 index 836eabb..65a05d5 100644 --- a/apfs-label/apfs-label.8 +++ b/apfs-label/apfs-label.8 @@ -14,7 +14,7 @@ is a simple tool that lists the index and label of all volumes in an APFS container, to help the user decide which one to mount with the driver. .SH OPTIONS .TP -.B \-v +.B \-v, \-\-version Print the version number of .B apfs-label and exit. diff --git a/apfs-label/apfs-label.c b/apfs-label/apfs-label.c index 07ef9ea..d94593c 100644 --- a/apfs-label/apfs-label.c +++ b/apfs-label/apfs-label.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include "version.h" @@ -306,14 +307,18 @@ static void list_labels(void) int main(int argc, char *argv[]) { - const char *filename = NULL; - if (argc == 0) exit(1); progname = argv[0]; + static const struct option long_options[] = { + { .name = "version", .has_arg = no_argument , .flag = NULL, .val = 'v' }, + { 0 }, + }; + while (1) { - int opt = getopt(argc, argv, "v"); + int opt_index = 0; + int opt = getopt_long(argc, argv, "v", long_options, &opt_index); if (opt == -1) break; @@ -328,7 +333,8 @@ int main(int argc, char *argv[]) if (optind != argc - 1) usage(); - filename = argv[optind]; + + const char *filename = argv[optind]; dev_fd = open(filename, O_RDONLY); if (dev_fd == -1) From 5449697abec4cdcc5b32890d195a9cd89f1cc524 Mon Sep 17 00:00:00 2001 From: Integral Date: Sat, 5 Oct 2024 21:16:11 +0800 Subject: [PATCH 2/2] apfs-snap: add long option --version --- apfs-snap/apfs-snap.8 | 2 +- apfs-snap/apfs-snap.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apfs-snap/apfs-snap.8 b/apfs-snap/apfs-snap.8 index 5357972..7113284 100644 --- a/apfs-snap/apfs-snap.8 +++ b/apfs-snap/apfs-snap.8 @@ -18,7 +18,7 @@ The label for the new snapshot must be specified in .IR name . .SH OPTIONS .TP -.B \-v +.B \-v, \-\-version Print the version number of .B apfs-snap and exit. diff --git a/apfs-snap/apfs-snap.c b/apfs-snap/apfs-snap.c index 320ce7d..7674e3b 100644 --- a/apfs-snap/apfs-snap.c +++ b/apfs-snap/apfs-snap.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "version.h" static char *progname; @@ -89,7 +90,13 @@ int main(int argc, char *argv[]) progname = argv[0]; while (1) { - int opt = getopt(argc, argv, "v"); + static const struct option long_options[] = { + { .name = "version", .has_arg = no_argument , .flag = NULL, .val = 'v' }, + { 0 }, + }; + + int opt_index = 0; + int opt = getopt_long(argc, argv, "v", long_options, &opt_index); if (opt == -1) break;