logo

utils-std

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

cmd/chown: Add getopt_long compatibility

Diffstat:

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

diff --git a/cmd/chown.c b/cmd/chown.c @@ -23,6 +23,9 @@ #include <string.h> // strerror, strcmp #include <sys/stat.h> // fstatat, S_ISDIR #include <unistd.h> // getopt +#ifdef HAS_GETOPT_LONG +#include <getopt.h> +#endif char *argv0 = NULL; @@ -200,7 +203,22 @@ main(int argc, char *argv[]) enum chown_follow_symlinks follow_symlinks = CHOWN_FOLLOW_UNK_SYMLINKS; int c = -1; +#ifdef HAS_GETOPT_LONG + // Strictly for GNUisms compatibility so no long-only options + // clang-format off + static struct option opts[] = { + {"no-dereference", no_argument, 0, 'h'}, + {"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, "+:hRHLPv", opts, NULL)) != -1) +#else while((c = getopt(argc, argv, ":hRHLPv")) != -1) +#endif { switch(c) {