logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: 951f0da1b0ca2763d05436f1d31fd0ca64f4537b
parent ef36c9eb162049dffbd722a8a9b22c23781c218d
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 25 Jul 2025 01:27:39 +0200

cmd/mkdir: add support for long options

Diffstat:

Mcmd/mkdir.c19+++++++++++++++++++
1 file changed, 19 insertions(+), 0 deletions(-)

diff --git a/cmd/mkdir.c b/cmd/mkdir.c @@ -4,6 +4,7 @@ #define _POSIX_C_SOURCE 200809L +#include "../config.h" #include "../libutils/getopt_nolong.h" #include "../libutils/lib_mkdir.h" #include "../libutils/mode.h" @@ -15,6 +16,9 @@ #include <string.h> // strerror #include <sys/stat.h> // mkdir #include <unistd.h> // getopt +#ifdef HAS_GETOPT_LONG +#include <getopt.h> +#endif const char *argv0 = "mkdir"; @@ -54,7 +58,22 @@ main(int argc, char *argv[]) const char *errstr = NULL; // clang-format on +#ifdef HAS_GETOPT_LONG + // Strictly for GNUisms compatibility so no long-only options + // clang-format off + static struct option opts[] = { + {"mode", required_argument, NULL, 'm'}, + {"parents", no_argument, NULL, 'p'}, + {"verbose", no_argument, NULL, 'v'}, + {0, 0, 0, 0}, + }; + // clang-format on + + // Need + as first character to get POSIX-style option parsing + for(int c = -1; (c = getopt_long(argc, argv, "+:pvm:", opts, NULL)) != -1;) +#else for(int c = -1; (c = getopt_nolong(argc, argv, ":pvm:")) != -1;) +#endif { switch(c) {