logo

utils-std

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

cmd/nice: add support for long options

Diffstat:

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

diff --git a/cmd/nice.c b/cmd/nice.c @@ -4,6 +4,7 @@ #define _POSIX_C_SOURCE 200809L #define _XOPEN_SOURCE 700 // nice() is in XSI +#include "../config.h" #include "../libutils/getopt_nolong.h" #include <assert.h> @@ -12,6 +13,9 @@ #include <stdlib.h> // abort #include <string.h> // strerror #include <unistd.h> // getopt, nice +#ifdef HAS_GETOPT_LONG +#include <getopt.h> +#endif const char *argv0 = "nice"; @@ -26,7 +30,20 @@ main(int argc, char *argv[]) { long incr = 0; +#ifdef HAS_GETOPT_LONG + // Strictly for GNUisms compatibility so no long-only options + // clang-format off + static struct option opts[] = { + {"adjustment", required_argument, NULL, 'n'}, + {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, "+:n:", opts, NULL)) != -1;) +#else for(int c = -1; (c = getopt_nolong(argc, argv, ":n:")) != -1;) +#endif { char *endptr = NULL;