]> Savannah Git Hosting - gnulib.git/commitdiff
getopt: clean up getopt.c and getopt1.c file headers
authorZack Weinberg <zackw@panix.com>
Thu, 6 Apr 2017 18:14:13 +0000 (11:14 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 6 Apr 2017 22:42:03 +0000 (15:42 -0700)
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.

ChangeLog
lib/getopt.c
lib/getopt1.c
m4/getopt.m4
modules/getopt-gnu
modules/getopt-posix

index 2c8109197bd21d5c21eff12cd2191c67f345dd58..e61efb8902706131f9faacc124ef6f207270ee53 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,25 @@
 2017-04-06  Zack Weinberg  <zackw@panix.com>
 
+       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
index 65ad56780ffed7654cd8f11c841ca6bfea74f1e2..559e03bed3dc99ffe47f9e8e20639efd113c9918 100644 (file)
 # define _(msgid) gettext (msgid)
 #endif
 
-#if defined _LIBC
-# include <wchar.h>
-#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;
-
-\f
-#if defined HAVE_DECL_GETENV && !HAVE_DECL_GETENV
-extern char *getenv ();
-#endif
 \f
 /* Exchange two adjacent subsequences of ARGV.
    One subsequence is elements [first_nonopt,last_nonopt)
index 988983f3e0fe0d6b8fd3f20af2fcc665eae256e5..b967d24f57be12cca2b8fff84854c838da80ddbd 100644 (file)
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 \f
-#ifdef _LIBC
-# include <getopt.h>
-#else
-# include <config.h>
-# include "getopt.h"
+#ifndef _LIBC
+#include "config.h"
 #endif
-#include "getopt_int.h"
-
-#include <stdio.h>
 
-/* This needs to come after some library #include
-   to get __GNU_LIBRARY__ defined.  */
-#ifdef __GNU_LIBRARY__
-#include <stdlib.h>
-#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 <stdio.h>
+#include <stdlib.h>
 
 int
 main (int argc, char **argv)
index 7a946263558bf23cdce6faaba65ae2a47dbc1136..f23d27b4144596f02714a402a67b1983d98cc087 100644 (file)
@@ -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])
-])
index 606013bdadc554ed1e36aaa7976222d634ef8595..9c348ed25ffcd316775839e11b846d7f163dae02 100644 (file)
@@ -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
index b82d6b27cdbaa1cd6fe2515a28f00bda321d8cea..642fc56e0b8004db095f92d280f3de1910233c72 100644 (file)
@@ -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