logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: a7c8206ff7ca98fc956e2d6763f6cbcbb8bbe070
parent 12ed54675dc68ed6fa4debbaeb96eb87acd15cba
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 25 Jul 2025 04:26:27 +0200

cmd/strings: add support for long options

Diffstat:

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

diff --git a/cmd/strings.c b/cmd/strings.c @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MPL-2.0 #define _POSIX_C_SOURCE 200809L +#include "../config.h" #include "../libutils/getopt_nolong.h" #include <ctype.h> /* isprint() */ @@ -13,6 +14,9 @@ #include <stdlib.h> /* strtol() */ #include <string.h> /* strerror(), strncmp() */ #include <unistd.h> /* read(), write(), close() */ +#ifdef HAS_GETOPT_LONG +#include <getopt.h> +#endif const char *argv0 = "strings"; size_t opt_min_strlen = 4; @@ -98,7 +102,22 @@ usage(void) int main(int argc, char *argv[]) { +#ifdef HAS_GETOPT_LONG + // Strictly for GNUisms compatibility so no long-only options + // clang-format off + static struct option opts[] = { + {"all", no_argument, NULL, 'a'}, + {"bytes", required_argument, NULL, 'n'}, + {"radix", required_argument, NULL, 't'}, + {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, "+:an:t:z", opts, NULL)) != -1;) +#else for(int c = -1; (c = getopt_nolong(argc, argv, ":an:t:z")) != -1;) +#endif { char *endptr = NULL;