logo

utils-std

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

cmd/ln: add support for long options

Diffstat:

Mcmd/ln.c22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/cmd/ln.c b/cmd/ln.c @@ -4,6 +4,7 @@ #define _POSIX_C_SOURCE 200809L +#include "../config.h" #include "../lib/bitmasks.h" #include "../libutils/getopt_nolong.h" @@ -21,6 +22,9 @@ #include <string.h> // strerror #include <sys/stat.h> #include <unistd.h> // getopt, symlink, link +#ifdef HAS_GETOPT_LONG +#include <getopt.h> +#endif const char *argv0 = "ln"; @@ -147,7 +151,25 @@ main(int argc, char *argv[]) { bool verbose = false; +#ifdef HAS_GETOPT_LONG + // Strictly for GNUisms compatibility so no long-only options + // clang-format off + static struct option opts[] = { + {"force", no_argument, NULL, 'f'}, + {"logical", no_argument, NULL, 'L'}, + {"no-dereference", no_argument, NULL, 'n'}, + {"physical", no_argument, NULL, 'P'}, + {"symbolic", no_argument, NULL, 's'}, + {"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, "+:fnsLPv", opts, NULL)) != -1;) +#else for(int c = -1; (c = getopt_nolong(argc, argv, ":fnsLPv")) != -1;) +#endif { switch(c) {