logo

utils-std

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

cmd/mknod: add support for long options

Diffstat:

Mcmd/mknod.c17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/cmd/mknod.c b/cmd/mknod.c @@ -5,6 +5,7 @@ #define _POSIX_C_SOURCE 200809L #define _XOPEN_SOURCE 700 // mknod is in XSI +#include "../config.h" #include "../libutils/getopt_nolong.h" #include "../libutils/mode.h" @@ -15,6 +16,9 @@ #include <sys/stat.h> // mknod #include <sys/sysmacros.h> // makedev #include <unistd.h> // getopt +#ifdef HAS_GETOPT_LONG +#include <getopt.h> +#endif mode_t filemask; const char *argv0 = "mknod"; @@ -54,7 +58,20 @@ main(int argc, char *argv[]) const char *errstr = NULL; +#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'}, + {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, "+:m:", opts, NULL)) != -1;) +#else for(int c = -1; (c = getopt_nolong(argc, argv, ":m:")) != -1;) +#endif { switch(c) {