summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2017-04-06 11:14:13 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2017-04-06 15:42:03 -0700
commitfbd6c988447f5793e08019e59f4789db892af698 (patch)
tree1702a4e1c7e770644d153622848542829d06e6c3
parent2dcee3a7916d833622476ddd464a549db9907f1b (diff)
downloadgnulib-fbd6c988447f5793e08019e59f4789db892af698.tar.gz
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.
-rw-r--r--ChangeLog20
-rw-r--r--lib/getopt.c9
-rw-r--r--lib/getopt1.c22
-rw-r--r--m4/getopt.m46
-rw-r--r--modules/getopt-gnu1
-rw-r--r--modules/getopt-posix1
6 files changed, 25 insertions, 34 deletions
diff --git a/ChangeLog b/ChangeLog
index 2c8109197b..e61efb8902 100644
--- 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
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 <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;
-
-
-#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
<http://www.gnu.org/licenses/>. */
-#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)
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