logo

utils-std

Collection of commonly available Unix tools
commit: ba20c714439833b7ac0cba723ae397400c8a9132
parent a993092bcd87f3f1c636d3667fcaf9411b106a4e
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 28 Jul 2024 00:30:44 +0200

cmd/chmod: Add getopt_long compatibility

Diffstat:

Mcmd/chmod.c18++++++++++++++++++
1 file changed, 18 insertions(+), 0 deletions(-)

diff --git a/cmd/chmod.c b/cmd/chmod.c @@ -21,6 +21,9 @@ #include <string.h> // strerror #include <sys/stat.h> // chmod, fstatat, S_ISDIR #include <unistd.h> // getopt +#ifdef HAS_GETOPT_LONG +#include <getopt.h> +#endif bool opt_c = false, opt_v = false; @@ -167,7 +170,22 @@ main(int argc, char *argv[]) bool opt_R = false; int c = -1; +#ifdef HAS_GETOPT_LONG + // Strictly for GNUisms compatibility so no long-only options + // clang-format off + static struct option opts[] = { + {"changes", no_argument, 0, 'c'}, + {"recursive", no_argument, 0, 'R'}, + {"verbose", no_argument, 0, 'v'}, + {0, 0, 0, 0}, + }; + // clang-format on + + // Need + as first character to get POSIX-style option parsing + while((c = getopt_long(argc, argv, "+:cRv", opts, NULL)) != -1) +#else while((c = getopt(argc, argv, ":cRv")) != -1) +#endif { switch(c) {