From: Zack Weinberg Date: Thu, 6 Apr 2017 18:14:13 +0000 (-0700) Subject: getopt: clean up getopt.c and getopt1.c file headers X-Git-Tag: v1.0~6295 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=fbd6c988447f5793e08019e59f4789db892af698;p=gnulib.git getopt: clean up getopt.c and getopt1.c file headers In getopt.c, there is no need to include wchar.h at all, and it is safe nowadays to assume that stdlib.h does declare getenv (several other gnulib modules make this assumption). In getopt1.c, the #ifdef _LIBC block at the top can be simplified by using "" inclusions consistently, and there is no actual need to include stdlib.h (except in the #ifdef TEST block, where it should be unconditional), nor to provide a backup definition of NULL at all. * lib/getopt1.c: Simplify #ifdeffage at top of file. Move inclusion of stdlib.h to #ifdef TEST block and make unconditional. Do not define NULL. * lib/getopt.c: Don't include wchar.h. No need to declare getenv. * m4/getopt.m4 (gl_PREREQ_GETENV): Delete. * modules/getopt-gnu, modules/getopt-posix: Don't call gl_PREREQ_GETENV. --- diff --git a/ChangeLog b/ChangeLog index 2c8109197b..e61efb8902 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,25 @@ 2017-04-06 Zack Weinberg + getopt: clean up getopt.c and getopt1.c file headers + + In getopt.c, there is no need to include wchar.h at all, and it is + safe nowadays to assume that stdlib.h does declare getenv (several + other gnulib modules make this assumption). + + In getopt1.c, the #ifdef _LIBC block at the top can be simplified + by using "" inclusions consistently, and there is no actual need to + include stdlib.h (except in the #ifdef TEST block, where it should be + unconditional), nor to provide a backup definition of NULL at all. + + * lib/getopt1.c: Simplify #ifdeffage at top of file. + Move inclusion of stdlib.h to #ifdef TEST block and make + unconditional. Do not define NULL. + * lib/getopt.c: Don't include wchar.h. No need to declare getenv. + * m4/getopt.m4 (gl_PREREQ_GETENV): Delete. + * modules/getopt-gnu, modules/getopt-posix: Don't call + gl_PREREQ_GETENV. + + getopt: harmonize comments with glibc The comments explaining how the behavior of 'getopt' varies depending diff --git a/lib/getopt.c b/lib/getopt.c index 65ad56780f..559e03bed3 100644 --- a/lib/getopt.c +++ b/lib/getopt.c @@ -37,10 +37,6 @@ # define _(msgid) gettext (msgid) #endif -#if defined _LIBC -# include -#endif - /* This implementation of 'getopt' has three modes for handling options interspersed with non-option arguments. It can stop scanning for options at the first non-option argument encountered, @@ -102,11 +98,6 @@ int optopt = '?'; /* Keep a global copy of all internal members of getopt_data. */ static struct _getopt_data getopt_data; - - -#if defined HAVE_DECL_GETENV && !HAVE_DECL_GETENV -extern char *getenv (); -#endif /* Exchange two adjacent subsequences of ARGV. One subsequence is elements [first_nonopt,last_nonopt) diff --git a/lib/getopt1.c b/lib/getopt1.c index 988983f3e0..b967d24f57 100644 --- a/lib/getopt1.c +++ b/lib/getopt1.c @@ -16,25 +16,12 @@ License along with the GNU C Library; if not, see . */ -#ifdef _LIBC -# include -#else -# include -# include "getopt.h" +#ifndef _LIBC +#include "config.h" #endif -#include "getopt_int.h" - -#include -/* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ -#include -#endif - -#ifndef NULL -#define NULL 0 -#endif +#include "getopt.h" +#include "getopt_int.h" int getopt_long (int argc, char *__getopt_argv_const *argv, const char *options, @@ -80,6 +67,7 @@ _getopt_long_only_r (int argc, char **argv, const char *options, #ifdef TEST #include +#include int main (int argc, char **argv) diff --git a/m4/getopt.m4 b/m4/getopt.m4 index 7a94626355..f23d27b414 100644 --- a/m4/getopt.m4 +++ b/m4/getopt.m4 @@ -360,9 +360,3 @@ AC_DEFUN([gl_GETOPT_SUBSTITUTE_HEADER], should be used.]) AC_SUBST([GETOPT_H]) ]) - -# Prerequisites of lib/getopt*. -AC_DEFUN([gl_PREREQ_GETOPT], -[ - AC_CHECK_DECLS_ONCE([getenv]) -]) diff --git a/modules/getopt-gnu b/modules/getopt-gnu index 606013bdad..9c348ed25f 100644 --- a/modules/getopt-gnu +++ b/modules/getopt-gnu @@ -13,7 +13,6 @@ gl_FUNC_GETOPT_GNU if test $REPLACE_GETOPT = 1; then AC_LIBOBJ([getopt]) AC_LIBOBJ([getopt1]) - gl_PREREQ_GETOPT dnl Arrange for unistd.h to include getopt.h. GNULIB_${gl_include_guard_prefix}_UNISTD_H_GETOPT=1 fi diff --git a/modules/getopt-posix b/modules/getopt-posix index b82d6b27cd..642fc56e0b 100644 --- a/modules/getopt-posix +++ b/modules/getopt-posix @@ -20,7 +20,6 @@ gl_FUNC_GETOPT_POSIX if test $REPLACE_GETOPT = 1; then AC_LIBOBJ([getopt]) AC_LIBOBJ([getopt1]) - gl_PREREQ_GETOPT dnl Arrange for unistd.h to include getopt.h. GNULIB_${gl_include_guard_prefix}_UNISTD_H_GETOPT=1 fi