From 13e14a6bfd9f29cbfeab0c5161d2a994f97532e7 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Thu, 26 Mar 2026 12:53:53 +0100 Subject: Update/gnulib 2026 03 (#2247) * Sync with the 202601-stable Gnulib code (4a3650d887) * Ignore more deps stuff in gnulib * Remove autogenerated gnulib files * Ignore more gnulib generated headers --- gl/getopt.c | 65 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 31 insertions(+), 34 deletions(-) (limited to 'gl/getopt.c') diff --git a/gl/getopt.c b/gl/getopt.c index 6b155e6c..406a406b 100644 --- a/gl/getopt.c +++ b/gl/getopt.c @@ -1,5 +1,5 @@ /* Getopt for GNU. - Copyright (C) 1987-2025 Free Software Foundation, Inc. + Copyright (C) 1987-2026 Free Software Foundation, Inc. This file is part of the GNU C Library and is also part of gnulib. Patches to this file should be submitted to both projects. @@ -42,7 +42,7 @@ # define funlockfile(fp) _IO_funlockfile (fp) #else # include "gettext.h" -# define _(msgid) dgettext ("gnulib", msgid) +# define _(msgid) dgettext (GNULIB_TEXT_DOMAIN, msgid) /* When used standalone, flockfile and funlockfile might not be available. */ # if (!defined _POSIX_THREAD_SAFE_FUNCTIONS \ @@ -133,7 +133,6 @@ exchange (char **argv, struct _getopt_data *d) int bottom = d->__first_nonopt; int middle = d->__last_nonopt; int top = d->optind; - char *tem; /* Exchange the shorter segment with the far end of the longer segment. That puts the shorter segment into the right place. @@ -151,7 +150,7 @@ exchange (char **argv, struct _getopt_data *d) /* Swap it with the top part of the top segment. */ for (i = 0; i < len; i++) { - tem = argv[bottom + i]; + char *tem = argv[bottom + i]; argv[bottom + i] = argv[top - (middle - bottom) + i]; argv[top - (middle - bottom) + i] = tem; } @@ -167,7 +166,7 @@ exchange (char **argv, struct _getopt_data *d) /* Swap it with the bottom part of the bottom segment. */ for (i = 0; i < len; i++) { - tem = argv[bottom + i]; + char *tem = argv[bottom + i]; argv[bottom + i] = argv[middle + i]; argv[middle + i] = tem; } @@ -196,28 +195,29 @@ process_long_option (int argc, char **argv, const char *optstring, int long_only, struct _getopt_data *d, int print_errors, const char *prefix) { - char *nameend; - size_t namelen; - const struct option *p; - const struct option *pfound = NULL; - int n_options; - int option_index; + char *nameend; for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++) /* Do nothing. */ ; - namelen = nameend - d->__nextchar; + size_t namelen = nameend - d->__nextchar; /* First look for an exact match, counting the options as a side effect. */ - for (p = longopts, n_options = 0; p->name; p++, n_options++) - if (!strncmp (p->name, d->__nextchar, namelen) - && namelen == strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - option_index = n_options; - break; - } + const struct option *pfound = NULL; + int n_options; + int option_index; + { + const struct option *p; + for (p = longopts, n_options = 0; p->name; p++, n_options++) + if (!strncmp (p->name, d->__nextchar, namelen) + && namelen == strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + option_index = n_options; + break; + } + } if (pfound == NULL) { @@ -227,6 +227,7 @@ process_long_option (int argc, char **argv, const char *optstring, unsigned char ambig_fallback; void *ambig_malloced = NULL; int indfound = -1; + const struct option *p; for (p = longopts, option_index = 0; p->name; p++, option_index++) if (!strncmp (p->name, d->__nextchar, namelen)) @@ -475,11 +476,11 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, const struct option *longopts, int *longind, int long_only, struct _getopt_data *d, int posixly_correct) { - int print_errors = d->opterr; - if (argc < 1) return -1; + int print_errors = d->opterr; + d->optarg = NULL; if (d->optind == 0 || !d->__initialized) @@ -594,11 +595,10 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, if (long_only && (argv[d->optind][2] || !strchr (optstring, argv[d->optind][1]))) { - int code; d->__nextchar = argv[d->optind] + 1; - code = process_long_option (argc, argv, optstring, longopts, - longind, long_only, d, - print_errors, "-"); + int code = process_long_option (argc, argv, optstring, longopts, + longind, long_only, d, + print_errors, "-"); if (code != -1) return code; } @@ -707,14 +707,12 @@ _getopt_internal (int argc, char **argv, const char *optstring, const struct option *longopts, int *longind, int long_only, int posixly_correct) { - int result; - getopt_data.optind = optind; getopt_data.opterr = opterr; - result = _getopt_internal_r (argc, argv, optstring, longopts, - longind, long_only, &getopt_data, - posixly_correct); + int result = _getopt_internal_r (argc, argv, optstring, longopts, + longind, long_only, &getopt_data, + posixly_correct); optind = getopt_data.optind; optarg = getopt_data.optarg; @@ -751,14 +749,13 @@ GETOPT_ENTRY(getopt, 1) int main (int argc, char **argv) { - int c; int digit_optind = 0; while (1) { int this_option_optind = optind ? optind : 1; - c = getopt (argc, argv, "abc:d:0123456789"); + int c = getopt (argc, argv, "abc:d:0123456789"); if (c == -1) break; -- cgit v1.2.3-74-g34f1