From bd78ca3d3d7b5ec2679af1ea3d23e278c81e01d8 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 22 Mar 2017 10:25:04 -0700 Subject: [PATCH] getopt: merge from glibc This does not change anything substantial; it merely simplifies hypothetical merges back to glibc. * lib/getopt.c, lib/getopt.in.h, lib/getopt1.c, lib/getopt_int.h: Change copyright notice to match what is in glibc. * lib/getopt.c: Reorder includes to match glibc. Remove uses of USE_IN_LIBIO. Remove 'register'. In __LIBC code, use __open_memstream rather than open_memstream and __glibc_likely instead of __builtin_expect. * lib/getopt.in.h (__posix_getopt) [!__GETOPT_PREFIX]: New decl. --- ChangeLog | 13 +++++++++ lib/getopt.c | 70 ++++++++++++++++++++++++------------------------ lib/getopt.in.h | 41 ++++++++++++++++++++-------- lib/getopt1.c | 22 +++++++-------- lib/getopt_int.h | 22 +++++++-------- 5 files changed, 100 insertions(+), 68 deletions(-) diff --git a/ChangeLog b/ChangeLog index 33bd6a12e4..ad7ae9e095 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2017-03-22 Paul Eggert + + getopt: merge from glibc + This does not change anything substantial; it merely simplifies + hypothetical merges back to glibc. + * lib/getopt.c, lib/getopt.in.h, lib/getopt1.c, lib/getopt_int.h: + Change copyright notice to match what is in glibc. + * lib/getopt.c: Reorder includes to match glibc. Remove uses of + USE_IN_LIBIO. Remove 'register'. In __LIBC code, use + __open_memstream rather than open_memstream and __glibc_likely + instead of __builtin_expect. + * lib/getopt.in.h (__posix_getopt) [!__GETOPT_PREFIX]: New decl. + 2017-03-21 Paul Eggert dfa: make [0-9] faster in non-C locales diff --git a/lib/getopt.c b/lib/getopt.c index e40ea8d5ea..03626c85a3 100644 --- a/lib/getopt.c +++ b/lib/getopt.c @@ -2,22 +2,22 @@ NOTE: getopt is part of the C library, so if you don't know what "Keep this file name-space clean" means, talk to drepper@gnu.org before changing it! - Copyright (C) 1987-1996, 1998-2004, 2006, 2008-2017 Free Software - Foundation, Inc. + Copyright (C) 1987-2017 Free Software Foundation, Inc. This file is part of the GNU C Library. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ #ifndef _LIBC # include @@ -27,8 +27,8 @@ #include #include -#include #include +#include #ifdef _LIBC # include @@ -37,7 +37,7 @@ # define _(msgid) gettext (msgid) #endif -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC # include #endif @@ -181,7 +181,7 @@ exchange (char **argv, struct _getopt_data *d) { /* Bottom segment is the short one. */ int len = middle - bottom; - register int i; + int i; /* Swap it with the top part of the top segment. */ for (i = 0; i < len; i++) @@ -198,7 +198,7 @@ exchange (char **argv, struct _getopt_data *d) { /* Top segment is the short one. */ int len = top - middle; - register int i; + int i; /* Swap it with the bottom part of the bottom segment. */ for (i = 0; i < len; i++) @@ -564,11 +564,11 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, first.next = ambig_list; ambig_list = &first; -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC char *buf = NULL; size_t buflen = 0; - FILE *fp = open_memstream (&buf, &buflen); + FILE *fp = __open_memstream (&buf, &buflen); if (fp != NULL) { fprintf (fp, @@ -584,7 +584,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, fputc_unlocked ('\n', fp); - if (__builtin_expect (fclose (fp) != EOF, 1)) + if (__glibc_likely (fclose (fp) != EOF)) { _IO_flockfile (stderr); @@ -642,7 +642,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, { if (print_errors) { -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC char *buf; int n; #endif @@ -650,7 +650,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, if (argv[d->optind - 1][1] == '-') { /* --option */ -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC n = __asprintf (&buf, _("\ %s: option '--%s' doesn't allow an argument\n"), argv[0], pfound->name); @@ -663,7 +663,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, else { /* +option or -option */ -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC n = __asprintf (&buf, _("\ %s: option '%c%s' doesn't allow an argument\n"), argv[0], argv[d->optind - 1][0], @@ -676,7 +676,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, #endif } -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC if (n >= 0) { _IO_flockfile (stderr); @@ -709,7 +709,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, { if (print_errors) { -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC char *buf; if (__asprintf (&buf, _("\ @@ -760,7 +760,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, { if (print_errors) { -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC char *buf; int n; #endif @@ -768,7 +768,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, if (argv[d->optind][1] == '-') { /* --option */ -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC n = __asprintf (&buf, _("%s: unrecognized option '--%s'\n"), argv[0], d->__nextchar); #else @@ -779,7 +779,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, else { /* +option or -option */ -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC n = __asprintf (&buf, _("%s: unrecognized option '%c%s'\n"), argv[0], argv[d->optind][0], d->__nextchar); #else @@ -788,7 +788,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, #endif } -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC if (n >= 0) { _IO_flockfile (stderr); @@ -826,19 +826,19 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, { if (print_errors) { -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC char *buf; int n; #endif -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC n = __asprintf (&buf, _("%s: invalid option -- '%c'\n"), argv[0], c); #else fprintf (stderr, _("%s: invalid option -- '%c'\n"), argv[0], c); #endif -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC if (n >= 0) { _IO_flockfile (stderr); @@ -884,7 +884,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, { if (print_errors) { -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC char *buf; if (__asprintf (&buf, @@ -958,7 +958,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, { if (print_errors) { -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC char *buf; if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"), @@ -998,7 +998,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, { if (print_errors) { -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC char *buf; if (__asprintf (&buf, _("\ @@ -1037,7 +1037,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, { if (print_errors) { -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC char *buf; if (__asprintf (&buf, _("\ @@ -1112,7 +1112,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, { if (print_errors) { -#if defined _LIBC && defined USE_IN_LIBIO +#if defined _LIBC char *buf; if (__asprintf (&buf, _("\ diff --git a/lib/getopt.in.h b/lib/getopt.in.h index 6cbad8e033..1008406131 100644 --- a/lib/getopt.in.h +++ b/lib/getopt.in.h @@ -1,20 +1,20 @@ /* Declarations for getopt. - Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2007, 2009-2017 Free Software - Foundation, Inc. + Copyright (C) 1989-2017 Free Software Foundation, Inc. This file is part of the GNU C Library. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ #ifndef _@GUARD_PREFIX@_GETOPT_H @@ -238,6 +238,25 @@ struct option extern int getopt (int ___argc, char *const *___argv, const char *__shortopts) __THROW _GL_ARG_NONNULL ((2, 3)); +#ifndef __GETOPT_PREFIX +# if defined __need_getopt && defined __USE_POSIX2 \ + && !defined __USE_POSIX_IMPLICITLY && !defined __USE_GNU +/* The GNU getopt has more functionality than the standard version. The + additional functionality can be disable at runtime. This redirection + helps to also do this at runtime. */ +# ifdef __REDIRECT + extern int __REDIRECT_NTH (getopt, (int ___argc, char *const *___argv, + const char *__shortopts), + __posix_getopt); +# else +extern int __posix_getopt (int ___argc, char *const *___argv, + const char *__shortopts) + __THROW _GL_ARG_NONNULL ((2, 3)); +# define getopt __posix_getopt +# endif +# endif +#endif + #ifndef __need_getopt extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv, const char *__shortopts, diff --git a/lib/getopt1.c b/lib/getopt1.c index 4d2e8cbac3..47c64e2fb6 100644 --- a/lib/getopt1.c +++ b/lib/getopt1.c @@ -1,20 +1,20 @@ /* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987-1994, 1996-1998, 2004, 2006, 2009-2017 Free Software - Foundation, Inc. + Copyright (C) 1987-2017 Free Software Foundation, Inc. This file is part of the GNU C Library. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ #ifdef _LIBC # include diff --git a/lib/getopt_int.h b/lib/getopt_int.h index a7ce0e9cc1..2786798ac9 100644 --- a/lib/getopt_int.h +++ b/lib/getopt_int.h @@ -1,20 +1,20 @@ /* Internal declarations for getopt. - Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2004, 2009-2017 Free Software - Foundation, Inc. + Copyright (C) 1989-2017 Free Software Foundation, Inc. This file is part of the GNU C Library. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ #ifndef _GETOPT_INT_H #define _GETOPT_INT_H 1 -- 2.39.5