summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2004-11-12 06:00:01 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2004-11-12 06:00:01 +0000
commit3c530e63c5977e1157fca280328d0ce48d35fc98 (patch)
treeb7eaa2b643784de7f78182950d9cde300f025e76
parente5839b5b28636c0ea3a39a20a39dbb8300aec3da (diff)
downloadcoreutils-3c530e63c5977e1157fca280328d0ce48d35fc98.tar.xz
Sync from gnulib and regenerate.
-rw-r--r--config.hin23
-rw-r--r--lib/ChangeLog5
-rw-r--r--lib/getopt.c17
-rw-r--r--lib/getopt1.c10
-rw-r--r--lib/getopt_.h56
-rw-r--r--lib/getopt_int.h9
-rw-r--r--m4/ChangeLog4
-rw-r--r--m4/getopt.m417
-rw-r--r--src/Makefile.in2
9 files changed, 85 insertions, 58 deletions
diff --git a/config.hin b/config.hin
index 6e419dec5..f630f0403 100644
--- a/config.hin
+++ b/config.hin
@@ -1485,6 +1485,10 @@
# 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
@@ -1512,16 +1516,6 @@
/* 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
@@ -1582,15 +1576,6 @@
/* 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
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 76c16dcaf..38e43daa2 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,8 @@
+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,
diff --git a/lib/getopt.c b/lib/getopt.c
index 92207f2bd..0fa7c0688 100644
--- a/lib/getopt.c
+++ b/lib/getopt.c
@@ -250,8 +250,8 @@ exchange (char **argv, struct _getopt_data *d)
/* 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
@@ -356,8 +356,9 @@ _getopt_initialize (int argc, char *const *argv, const char *optstring,
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.
@@ -370,7 +371,8 @@ _getopt_initialize (int argc, char *const *argv, const char *optstring,
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)
{
@@ -1135,7 +1137,8 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
}
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;
@@ -1154,7 +1157,7 @@ _getopt_internal (int argc, char *const *argv, const char *optstring,
}
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,
diff --git a/lib/getopt1.c b/lib/getopt1.c
index 706f59c08..a6fdee5a5 100644
--- a/lib/getopt1.c
+++ b/lib/getopt1.c
@@ -41,14 +41,14 @@
#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)
{
@@ -62,14 +62,16 @@ _getopt_long_r (int argc, char *const *argv, const char *options,
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)
{
diff --git a/lib/getopt_.h b/lib/getopt_.h
index 9774110d9..d933ce780 100644
--- a/lib/getopt_.h
+++ b/lib/getopt_.h
@@ -23,6 +23,48 @@
# 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
@@ -144,22 +186,16 @@ struct option
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;
diff --git a/lib/getopt_int.h b/lib/getopt_int.h
index 0c5eddeca..158a53a09 100644
--- a/lib/getopt_int.h
+++ b/lib/getopt_int.h
@@ -20,7 +20,7 @@
#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);
@@ -110,17 +110,18 @@ struct _getopt_data
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,
diff --git a/m4/ChangeLog b/m4/ChangeLog
index 3d16a9a5e..6534d0877 100644
--- a/m4/ChangeLog
+++ b/m4/ChangeLog
@@ -1,3 +1,7 @@
+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.
diff --git a/m4/getopt.m4 b/m4/getopt.m4
index c3cf64727..be36ddd2e 100644
--- a/m4/getopt.m4
+++ b/m4/getopt.m4
@@ -1,4 +1,4 @@
-# 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
@@ -15,18 +15,9 @@ AC_DEFUN([gl_GETOPT_SUBSTITUTE],
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])
])
diff --git a/src/Makefile.in b/src/Makefile.in
index d971fb03a..e096db958 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -940,7 +940,7 @@ uninstall-binPROGRAMS:
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 \