logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: d09948a62fc69d2e3949f9237cd383f5bef19ecc
parent 673f695d7b4acfd7feada3722ecf1f7c8f0b131f
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 22 Nov 2024 12:54:16 +0100

cmd/mktemp: add getopt_long support

Diffstat:

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

diff --git a/cmd/mktemp.c b/cmd/mktemp.c @@ -12,6 +12,9 @@ #include <stdlib.h> // getenv #include <string.h> // strerror #include <unistd.h> // getopt, getentropy +#ifdef HAS_GETOPT_LONG +#include <getopt.h> +#endif const char *argv0 = "mktemp"; @@ -69,7 +72,23 @@ main(int argc, char *argv[]) const char *tmpdir = NULL; int c = -1; +#ifdef HAS_GETOPT_LONG + // Strictly for GNUisms compatibility so no long-only options + // clang-format off + static struct option opts[] = { + {"directory", no_argument, 0, 'd'}, + {"dry-run", required_argument, 0, 'u'}, + {"quiet", no_argument, 0, 'q'}, + {"tmpdir", required_argument, 0, 'p'}, + {0, 0, 0, 0}, + }; + // clang-format on + + // Need + as first character to get POSIX-style option parsing + while((c = getopt_long(argc, argv, "+:dqp:tu", opts, NULL)) != -1) +#else while((c = getopt(argc, argv, ":dqp:tu")) != -1) +#endif { switch(c) {