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
# 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,
/* 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)
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,
#ifdef TEST
#include <stdio.h>
+#include <stdlib.h>
int
main (int argc, char **argv)
should be used.])
AC_SUBST([GETOPT_H])
])
-
-# Prerequisites of lib/getopt*.
-AC_DEFUN([gl_PREREQ_GETOPT],
-[
- AC_CHECK_DECLS_ONCE([getenv])
-])
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
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