summaryrefslogtreecommitdiff
path: root/lib/getopt_.h
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 /lib/getopt_.h
parente5839b5b28636c0ea3a39a20a39dbb8300aec3da (diff)
downloadcoreutils-3c530e63c5977e1157fca280328d0ce48d35fc98.tar.xz
Sync from gnulib and regenerate.
Diffstat (limited to 'lib/getopt_.h')
-rw-r--r--lib/getopt_.h56
1 files changed, 46 insertions, 10 deletions
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;