summaryrefslogtreecommitdiffstats
path: root/lib/getopt.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/getopt.h')
-rw-r--r--lib/getopt.h53
1 files changed, 25 insertions, 28 deletions
diff --git a/lib/getopt.h b/lib/getopt.h
index b13f242d..2d141edf 100644
--- a/lib/getopt.h
+++ b/lib/getopt.h
@@ -23,6 +23,18 @@
#ifndef _GETOPT_H
#define _GETOPT_H 1
+/*
+ * The operating system may or may not provide getopt_long(), and if
+ * so it may or may not be a version we are willing to use. Our
+ * strategy is to declare getopt here, and then provide code unless
+ * the supplied version is adequate. The difficult case is when a
+ * declaration for getopt is provided, as our declaration must match.
+ *
+ * XXX Arguably this version should be named differently, and the
+ * local names defined to refer to the system version when we choose
+ * to use the system version.
+ */
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -81,11 +93,7 @@ extern int optopt;
struct option
{
-#if defined (__STDC__) && __STDC__
const char *name;
-#else
- char *name;
-#endif
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
@@ -99,24 +107,20 @@ struct option
#define required_argument 1
#define optional_argument 2
-#if defined (__STDC__) && __STDC__
-/* HAVE_DECL_* is a three-state macro: undefined, 0 or 1. If it is
- undefined, we haven't run the autoconf check so provide the
- declaration without arguments. If it is 0, we checked and failed
- to find the declaration so provide a fully prototyped one. If it
- is 1, we found it so don't provide any declaration at all. */
-#if !HAVE_DECL_GETOPT
-#if defined (__GNU_LIBRARY__) || defined (HAVE_DECL_GETOPT)
-/* Many other libraries have conflicting prototypes for getopt, with
- differences in the consts, in unistd.h. To avoid compilation
- errors, only prototype getopt for the GNU C library. */
+#if REALLY_NEED_PLAIN_GETOPT /*------------------------------------*/
+
+/* getopt is defined in POSIX.2. Assume that if the system defines
+ * getopt that it complies with POSIX.2. If not, an autoconf test
+ * should be written to define NONPOSIX_GETOPT_DEFINITION.
+ */
+
+# ifndef NONPOSIX_GETOPT_DEFINITION
extern int getopt (int argc, char *const *argv, const char *shortopts);
-#else
-#ifndef __cplusplus
-extern int getopt ();
-#endif /* __cplusplus */
-#endif
-#endif /* !HAVE_DECL_GETOPT */
+# else /* NONPOSIX_GETOPT_DEFINITION */
+extern int getopt (void);
+# endif /* NONPOSIX_GETOPT_DEFINITION */
+
+#endif /* REALLY_NEED_PLAIN_GETOPT ------------------------------------*/
extern int getopt_long (int argc, char *const *argv, const char *shortopts,
const struct option *longopts, int *longind);
@@ -129,13 +133,6 @@ extern int _getopt_internal (int argc, char *const *argv,
const char *shortopts,
const struct option *longopts, int *longind,
int long_only);
-#else /* not __STDC__ */
-extern int getopt ();
-extern int getopt_long ();
-extern int getopt_long_only ();
-
-extern int _getopt_internal ();
-#endif /* __STDC__ */
#ifdef __cplusplus
}