# undef __EXTENSIONS__
#endif
+/* Define to rpl_ if the getopt replacement functions and variables should be
+ used. */
+#undef __GETOPT_PREFIX
+
/* Define like PROTOTYPES; this can be used by system headers. */
#undef __PROTOTYPES
/* Define to a replacement function name for getline(). */
#undef getline
-/* Define to rpl_getopt if the replacement function should be used. */
-#undef getopt
-
-/* Define to rpl_getopt_long if the replacement function should be used. */
-#undef getopt_long
-
-/* Define to rpl_getopt_long_only if the replacement function should be used.
- */
-#undef getopt_long_only
-
/* Define to rpl_gettimeofday if the replacement function should be used. */
#undef gettimeofday
/* Define to `long' if <sys/types.h> does not define. */
#undef off_t
-/* Define to rpl_optarg if the replacement variable should be used. */
-#undef optarg
-
-/* Define to rpl_optind if the replacement variable should be used. */
-#undef optind
-
-/* Define to rpl_optopt if the replacement variable should be used. */
-#undef optopt
-
/* Define to `int' if <sys/types.h> does not define. */
#undef pid_t
+2004-11-11 Paul Eggert <eggert@cs.ucla.edu>
+
+ * getopt.c, getopt1.c, getopt_.h, getopt_int.h:
+ Sync from gnulib.
+
2004-11-10 Paul Eggert <eggert@cs.ucla.edu>
* allocsa.h, mbswidth.c, mktime.c, readlink.c, getdate.y,
/* Initialize the internal data when the first call is made. */
static const char *
-_getopt_initialize (int argc, char *const *argv, const char *optstring,
- struct _getopt_data *d)
+_getopt_initialize (int argc, char *__getopt_argv_const *argv,
+ const char *optstring, struct _getopt_data *d)
{
/* Start processing options with ARGV-element 1 (since ARGV-element 0
is the program name); the sequence of previously skipped
if the `flag' field is zero.
The elements of ARGV aren't really const, because we permute them.
- But we pretend they're const in the prototype to be compatible
- with other systems.
+ If __getopt_argv_const is defined to const, pretend they're
+ const in the prototype to be compatible with Posix.
+ But tell the truth if __getopt_argv_const is defined to empty.
LONGOPTS is a vector of `struct option' terminated by an
element containing a name which is zero.
long-named options. */
int
-_getopt_internal_r (int argc, char *const *argv, const char *optstring,
+_getopt_internal_r (int argc, char *__getopt_argv_const *argv,
+ const char *optstring,
const struct option *longopts, int *longind,
int long_only, struct _getopt_data *d)
{
}
int
-_getopt_internal (int argc, char *const *argv, const char *optstring,
+_getopt_internal (int argc, char *__getopt_argv_const *argv,
+ const char *optstring,
const struct option *longopts, int *longind, int long_only)
{
int result;
}
int
-getopt (int argc, char *const *argv, const char *optstring)
+getopt (int argc, char *__getopt_argv_const *argv, const char *optstring)
{
return _getopt_internal (argc, argv, optstring,
(const struct option *) 0,
#endif
int
-getopt_long (int argc, char *const *argv, const char *options,
+getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
const struct option *long_options, int *opt_index)
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
}
int
-_getopt_long_r (int argc, char *const *argv, const char *options,
+_getopt_long_r (int argc, char *__getopt_argv_const *argv, const char *options,
const struct option *long_options, int *opt_index,
struct _getopt_data *d)
{
instead. */
int
-getopt_long_only (int argc, char *const *argv, const char *options,
+getopt_long_only (int argc, char *__getopt_argv_const *argv,
+ const char *options,
const struct option *long_options, int *opt_index)
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
}
int
-_getopt_long_only_r (int argc, char *const *argv, const char *options,
+_getopt_long_only_r (int argc, char *__getopt_argv_const *argv,
+ const char *options,
const struct option *long_options, int *opt_index,
struct _getopt_data *d)
{
# define _GETOPT_H 1
#endif
+/* Standalone applications should #define __GETOPT_PREFIX to an
+ identifier that prefixes the external functions and variables
+ defined in this header. When this happens, include the
+ headers that might declare getopt so that they will not cause
+ confusion if included after this file. Then systematically rename
+ identifiers so that they do not collide with the system functions
+ and variables. Renaming avoids problems with some compilers and
+ linkers. */
+#if defined __GETOPT_PREFIX && !defined __need_getopt
+# include <stdlib.h>
+# include <stdio.h>
+# if HAVE_UNISTD_H
+# include <unistd.h>
+# endif
+# undef getopt
+# undef getopt_long
+# undef getopt_long_only
+# undef optarg
+# undef opterr
+# undef optind
+# undef optopt
+# define getopt __GETOPT_PREFIX##getopt
+# define getopt_long __GETOPT_PREFIX##getopt_long
+# define getopt_long_only __GETOPT_PREFIX##getopt_long_only
+# define optarg __GETOPT_PREFIX##optarg
+# define opterr __GETOPT_PREFIX##opterr
+# define optind __GETOPT_PREFIX##optind
+# define optopt __GETOPT_PREFIX##optopt
+#endif
+
+/* The elements of the ARGV arguments to getopt aren't really const,
+ because we permute them. For glibc, __getopt_argv_const is const
+ so that prototypes pretend the elements are const, to be compatible
+ with Posix. However, drop this pretense for standalone
+ applications, since it's not needed there and it's safer not to lie
+ to compilers. */
+#ifdef __GETOPT_PREFIX
+# define __getopt_argv_const /* empty */
+#else
+# define __getopt_argv_const const
+#endif
+
/* If __GNU_LIBRARY__ is not already defined, either we are being used
standalone, or this is the first header included in the source file.
If we are being used with glibc, we need to include <features.h>, but
arguments to the option '\0'. This behavior is specific to the GNU
`getopt'. */
-#ifdef __GNU_LIBRARY__
-/* Many other libraries have conflicting prototypes for getopt, with
- differences in the consts, in stdlib.h. To avoid compilation
- errors, only prototype getopt for the GNU C library. */
-extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
+extern int getopt (int ___argc, char *__getopt_argv_const *___argv,
+ const char *__shortopts)
__THROW;
-#else /* not __GNU_LIBRARY__ */
-extern int getopt ();
-#endif /* __GNU_LIBRARY__ */
#ifndef __need_getopt
-extern int getopt_long (int ___argc, char *const *___argv,
+extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind)
__THROW;
-extern int getopt_long_only (int ___argc, char *const *___argv,
+extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind)
__THROW;
#ifndef _GETOPT_INT_H
#define _GETOPT_INT_H 1
-extern int _getopt_internal (int ___argc, char *const *___argv,
+extern int _getopt_internal (int ___argc, char *__getopt_argv_const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind,
int __long_only);
default values and to clear the initialization flag. */
#define _GETOPT_DATA_INITIALIZER { 1, 1 }
-extern int _getopt_internal_r (int ___argc, char *const *___argv,
+extern int _getopt_internal_r (int ___argc, char *__getopt_argv_const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind,
int __long_only, struct _getopt_data *__data);
-extern int _getopt_long_r (int ___argc, char *const *___argv,
+extern int _getopt_long_r (int ___argc, char *__getopt_argv_const *___argv,
const char *__shortopts,
const struct option *__longopts, int *__longind,
struct _getopt_data *__data);
-extern int _getopt_long_only_r (int ___argc, char *const *___argv,
+extern int _getopt_long_only_r (int ___argc,
+ char *__getopt_argv_const *___argv,
const char *__shortopts,
const struct option *__longopts,
int *__longind,
+2004-11-11 Paul Eggert <eggert@cs.ucla.edu>
+
+ * getopt.m4: Sync from gnulib.
+
2004-11-06 Jim Meyering <jim@meyering.net>
* jm-macros.m4: Don't require gl_FUNC_FPENDING.
-# getopt.m4 serial 4
+# getopt.m4 serial 6
dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License. As a special exception to the GNU General
GETOPT_H=getopt.h
AC_LIBOBJ([getopt])
AC_LIBOBJ([getopt1])
- AC_DEFINE([optarg], [rpl_optarg],
- [Define to rpl_optarg if the replacement variable should be used.])
- AC_DEFINE([optind], [rpl_optind],
- [Define to rpl_optind if the replacement variable should be used.])
- AC_DEFINE([optopt], [rpl_optopt],
- [Define to rpl_optopt if the replacement variable should be used.])
- AC_DEFINE([getopt], [rpl_getopt],
- [Define to rpl_getopt if the replacement function should be used.])
- AC_DEFINE([getopt_long], [rpl_getopt_long],
- [Define to rpl_getopt_long if the replacement function should be used.])
- AC_DEFINE([getopt_long_only], [rpl_getopt_long_only],
- [Define to rpl_getopt_long_only if the replacement function should be used.])
+ AC_DEFINE([__GETOPT_PREFIX], [[rpl_]],
+ [Define to rpl_ if the getopt replacement functions and variables
+ should be used.])
AC_SUBST([GETOPT_H])
])
done
clean-binPROGRAMS:
- -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
+ -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) > /dev/null 2>&1 || /bin/rm -f $(bin_PROGRAMS)
installcheck-binPROGRAMS: $(bin_PROGRAMS)
bad=0; pid=$$$$; list="$(bin_PROGRAMS)"; for p in $$list; do \