diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2026-03-26 12:53:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-26 12:53:53 +0100 |
| commit | 13e14a6bfd9f29cbfeab0c5161d2a994f97532e7 (patch) | |
| tree | 3aa7186fe092e42783dc7e981dc39a74ea61c466 /gl/getopt.c | |
| parent | 9d8503f90ef25b2cecd324dc118e441f40233ea8 (diff) | |
| download | monitoring-plugins-13e14a6bfd9f29cbfeab0c5161d2a994f97532e7.tar.gz | |
* Sync with the 202601-stable Gnulib code (4a3650d887)
* Ignore more deps stuff in gnulib
* Remove autogenerated gnulib files
* Ignore more gnulib generated headers
Diffstat (limited to 'gl/getopt.c')
| -rw-r--r-- | gl/getopt.c | 65 |
1 files changed, 31 insertions, 34 deletions
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 @@ | |||
| 1 | /* Getopt for GNU. | 1 | /* Getopt for GNU. |
| 2 | Copyright (C) 1987-2025 Free Software Foundation, Inc. | 2 | Copyright (C) 1987-2026 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library and is also part of gnulib. | 3 | This file is part of the GNU C Library and is also part of gnulib. |
| 4 | Patches to this file should be submitted to both projects. | 4 | Patches to this file should be submitted to both projects. |
| 5 | 5 | ||
| @@ -42,7 +42,7 @@ | |||
| 42 | # define funlockfile(fp) _IO_funlockfile (fp) | 42 | # define funlockfile(fp) _IO_funlockfile (fp) |
| 43 | #else | 43 | #else |
| 44 | # include "gettext.h" | 44 | # include "gettext.h" |
| 45 | # define _(msgid) dgettext ("gnulib", msgid) | 45 | # define _(msgid) dgettext (GNULIB_TEXT_DOMAIN, msgid) |
| 46 | /* When used standalone, flockfile and funlockfile might not be | 46 | /* When used standalone, flockfile and funlockfile might not be |
| 47 | available. */ | 47 | available. */ |
| 48 | # if (!defined _POSIX_THREAD_SAFE_FUNCTIONS \ | 48 | # if (!defined _POSIX_THREAD_SAFE_FUNCTIONS \ |
| @@ -133,7 +133,6 @@ exchange (char **argv, struct _getopt_data *d) | |||
| 133 | int bottom = d->__first_nonopt; | 133 | int bottom = d->__first_nonopt; |
| 134 | int middle = d->__last_nonopt; | 134 | int middle = d->__last_nonopt; |
| 135 | int top = d->optind; | 135 | int top = d->optind; |
| 136 | char *tem; | ||
| 137 | 136 | ||
| 138 | /* Exchange the shorter segment with the far end of the longer segment. | 137 | /* Exchange the shorter segment with the far end of the longer segment. |
| 139 | That puts the shorter segment into the right place. | 138 | That puts the shorter segment into the right place. |
| @@ -151,7 +150,7 @@ exchange (char **argv, struct _getopt_data *d) | |||
| 151 | /* Swap it with the top part of the top segment. */ | 150 | /* Swap it with the top part of the top segment. */ |
| 152 | for (i = 0; i < len; i++) | 151 | for (i = 0; i < len; i++) |
| 153 | { | 152 | { |
| 154 | tem = argv[bottom + i]; | 153 | char *tem = argv[bottom + i]; |
| 155 | argv[bottom + i] = argv[top - (middle - bottom) + i]; | 154 | argv[bottom + i] = argv[top - (middle - bottom) + i]; |
| 156 | argv[top - (middle - bottom) + i] = tem; | 155 | argv[top - (middle - bottom) + i] = tem; |
| 157 | } | 156 | } |
| @@ -167,7 +166,7 @@ exchange (char **argv, struct _getopt_data *d) | |||
| 167 | /* Swap it with the bottom part of the bottom segment. */ | 166 | /* Swap it with the bottom part of the bottom segment. */ |
| 168 | for (i = 0; i < len; i++) | 167 | for (i = 0; i < len; i++) |
| 169 | { | 168 | { |
| 170 | tem = argv[bottom + i]; | 169 | char *tem = argv[bottom + i]; |
| 171 | argv[bottom + i] = argv[middle + i]; | 170 | argv[bottom + i] = argv[middle + i]; |
| 172 | argv[middle + i] = tem; | 171 | argv[middle + i] = tem; |
| 173 | } | 172 | } |
| @@ -196,28 +195,29 @@ process_long_option (int argc, char **argv, const char *optstring, | |||
| 196 | int long_only, struct _getopt_data *d, | 195 | int long_only, struct _getopt_data *d, |
| 197 | int print_errors, const char *prefix) | 196 | int print_errors, const char *prefix) |
| 198 | { | 197 | { |
| 199 | char *nameend; | ||
| 200 | size_t namelen; | ||
| 201 | const struct option *p; | ||
| 202 | const struct option *pfound = NULL; | ||
| 203 | int n_options; | ||
| 204 | int option_index; | ||
| 205 | 198 | ||
| 199 | char *nameend; | ||
| 206 | for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++) | 200 | for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++) |
| 207 | /* Do nothing. */ ; | 201 | /* Do nothing. */ ; |
| 208 | namelen = nameend - d->__nextchar; | 202 | size_t namelen = nameend - d->__nextchar; |
| 209 | 203 | ||
| 210 | /* First look for an exact match, counting the options as a side | 204 | /* First look for an exact match, counting the options as a side |
| 211 | effect. */ | 205 | effect. */ |
| 212 | for (p = longopts, n_options = 0; p->name; p++, n_options++) | 206 | const struct option *pfound = NULL; |
| 213 | if (!strncmp (p->name, d->__nextchar, namelen) | 207 | int n_options; |
| 214 | && namelen == strlen (p->name)) | 208 | int option_index; |
| 215 | { | 209 | { |
| 216 | /* Exact match found. */ | 210 | const struct option *p; |
| 217 | pfound = p; | 211 | for (p = longopts, n_options = 0; p->name; p++, n_options++) |
| 218 | option_index = n_options; | 212 | if (!strncmp (p->name, d->__nextchar, namelen) |
| 219 | break; | 213 | && namelen == strlen (p->name)) |
| 220 | } | 214 | { |
| 215 | /* Exact match found. */ | ||
| 216 | pfound = p; | ||
| 217 | option_index = n_options; | ||
| 218 | break; | ||
| 219 | } | ||
| 220 | } | ||
| 221 | 221 | ||
| 222 | if (pfound == NULL) | 222 | if (pfound == NULL) |
| 223 | { | 223 | { |
| @@ -227,6 +227,7 @@ process_long_option (int argc, char **argv, const char *optstring, | |||
| 227 | unsigned char ambig_fallback; | 227 | unsigned char ambig_fallback; |
| 228 | void *ambig_malloced = NULL; | 228 | void *ambig_malloced = NULL; |
| 229 | int indfound = -1; | 229 | int indfound = -1; |
| 230 | const struct option *p; | ||
| 230 | 231 | ||
| 231 | for (p = longopts, option_index = 0; p->name; p++, option_index++) | 232 | for (p = longopts, option_index = 0; p->name; p++, option_index++) |
| 232 | if (!strncmp (p->name, d->__nextchar, namelen)) | 233 | if (!strncmp (p->name, d->__nextchar, namelen)) |
| @@ -475,11 +476,11 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 475 | const struct option *longopts, int *longind, | 476 | const struct option *longopts, int *longind, |
| 476 | int long_only, struct _getopt_data *d, int posixly_correct) | 477 | int long_only, struct _getopt_data *d, int posixly_correct) |
| 477 | { | 478 | { |
| 478 | int print_errors = d->opterr; | ||
| 479 | |||
| 480 | if (argc < 1) | 479 | if (argc < 1) |
| 481 | return -1; | 480 | return -1; |
| 482 | 481 | ||
| 482 | int print_errors = d->opterr; | ||
| 483 | |||
| 483 | d->optarg = NULL; | 484 | d->optarg = NULL; |
| 484 | 485 | ||
| 485 | if (d->optind == 0 || !d->__initialized) | 486 | if (d->optind == 0 || !d->__initialized) |
| @@ -594,11 +595,10 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, | |||
| 594 | if (long_only && (argv[d->optind][2] | 595 | if (long_only && (argv[d->optind][2] |
| 595 | || !strchr (optstring, argv[d->optind][1]))) | 596 | || !strchr (optstring, argv[d->optind][1]))) |
| 596 | { | 597 | { |
| 597 | int code; | ||
| 598 | d->__nextchar = argv[d->optind] + 1; | 598 | d->__nextchar = argv[d->optind] + 1; |
| 599 | code = process_long_option (argc, argv, optstring, longopts, | 599 | int code = process_long_option (argc, argv, optstring, longopts, |
| 600 | longind, long_only, d, | 600 | longind, long_only, d, |
| 601 | print_errors, "-"); | 601 | print_errors, "-"); |
| 602 | if (code != -1) | 602 | if (code != -1) |
| 603 | return code; | 603 | return code; |
| 604 | } | 604 | } |
| @@ -707,14 +707,12 @@ _getopt_internal (int argc, char **argv, const char *optstring, | |||
| 707 | const struct option *longopts, int *longind, int long_only, | 707 | const struct option *longopts, int *longind, int long_only, |
| 708 | int posixly_correct) | 708 | int posixly_correct) |
| 709 | { | 709 | { |
| 710 | int result; | ||
| 711 | |||
| 712 | getopt_data.optind = optind; | 710 | getopt_data.optind = optind; |
| 713 | getopt_data.opterr = opterr; | 711 | getopt_data.opterr = opterr; |
| 714 | 712 | ||
| 715 | result = _getopt_internal_r (argc, argv, optstring, longopts, | 713 | int result = _getopt_internal_r (argc, argv, optstring, longopts, |
| 716 | longind, long_only, &getopt_data, | 714 | longind, long_only, &getopt_data, |
| 717 | posixly_correct); | 715 | posixly_correct); |
| 718 | 716 | ||
| 719 | optind = getopt_data.optind; | 717 | optind = getopt_data.optind; |
| 720 | optarg = getopt_data.optarg; | 718 | optarg = getopt_data.optarg; |
| @@ -751,14 +749,13 @@ GETOPT_ENTRY(getopt, 1) | |||
| 751 | int | 749 | int |
| 752 | main (int argc, char **argv) | 750 | main (int argc, char **argv) |
| 753 | { | 751 | { |
| 754 | int c; | ||
| 755 | int digit_optind = 0; | 752 | int digit_optind = 0; |
| 756 | 753 | ||
| 757 | while (1) | 754 | while (1) |
| 758 | { | 755 | { |
| 759 | int this_option_optind = optind ? optind : 1; | 756 | int this_option_optind = optind ? optind : 1; |
| 760 | 757 | ||
| 761 | c = getopt (argc, argv, "abc:d:0123456789"); | 758 | int c = getopt (argc, argv, "abc:d:0123456789"); |
| 762 | if (c == -1) | 759 | if (c == -1) |
| 763 | break; | 760 | break; |
| 764 | 761 | ||
