summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgdt <gdt>2005-08-10 13:20:03 +0000
committergdt <gdt>2005-08-10 13:20:03 +0000
commit0312f0cd92e26d8097145d00dfad4638ed687f02 (patch)
tree0eb8c8b39c1b20cbac4690f85d5b7d4846d78b7e
parent01018ce479cce0af61d3797e5200cc340fe6ec0e (diff)
2005-08-10 Greg Troxel <gdt@fnord.ir.bbn.com>
* getopt.h: Don't declare getopt (rather than getopt_long), since quagga doesn't need it. * getopt.c (getopt): Don't define getopt. Fixes build breakage on NetBSD, and seems likely to work on most platforms since it avoids the entire issue of system getopt declarations and whether they conform to POSIX.2. Note that this change doesn't address system getopt_long declarations, but also doesn't change anything about getopt_long.
-rw-r--r--lib/ChangeLog6
-rw-r--r--lib/getopt.c4
-rw-r--r--lib/getopt.h45
3 files changed, 41 insertions, 14 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 42e80bd2..8c69a9af 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,9 @@
+2005-08-10 Greg Troxel <gdt@fnord.ir.bbn.com>
+
+ * getopt.h: Don't declare getopt (rather than getopt_long), since
+ quagga doesn't need it.
+ * getopt.c (getopt): Don't define getopt.
+
2005-07-26 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* prefix.c: (prefix_ipv4_new, prefix_ipv6_new): Call prefix_new
to allocate the memory to make sure that all struct prefix pointers
diff --git a/lib/getopt.c b/lib/getopt.c
index 329e9395..c784fb6c 100644
--- a/lib/getopt.c
+++ b/lib/getopt.c
@@ -969,6 +969,8 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
}
}
+#ifdef REALLY_NEED_PLAIN_GETOPT
+
int
getopt (argc, argv, optstring)
int argc;
@@ -981,6 +983,8 @@ getopt (argc, argv, optstring)
0);
}
+#endif /* REALLY_NEED_PLAIN_GETOPT */
+
#endif /* Not ELIDE_CODE. */
#ifdef TEST
diff --git a/lib/getopt.h b/lib/getopt.h
index dceb0301..b359a47b 100644
--- a/lib/getopt.h
+++ b/lib/getopt.h
@@ -22,6 +22,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
@@ -99,23 +111,23 @@ struct option
#define optional_argument 2
#if defined (__STDC__) && __STDC__
-#if defined (__GNU_LIBRARY__) \
- || defined (__EXTENSIONS__) \
- || defined (_GETOPT_DEFINED_) \
- || defined (_GETOPT_DECLARED)
-/* Many other libraries have conflicting prototypes for getopt, with
- differences in the consts, in stdlib.h. To avoid compilation
- errors, only prototype getopt for systems we know have compatible
- getopt.
- glibc: __GNU_LIBRARY__
- solaris: __EXTENSIONS__
- OpenBSD: _GETOPT_DEFINED_
- FreeBSD: _GETOPT_DECLARED
+
+#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 /* not __GNU_LIBRARY__ or __EXTENSIONS__ */
+#else /* NONPOSIX_GETOPT_DEFINITION */
extern int getopt (void);
-#endif /* __GNU_LIBRARY__ */
+#endif /* NONPOSIX_GETOPT_DEFINITION */
+
+#endif
+
+
extern int getopt_long (int argc, char *const *argv, const char *shortopts,
const struct option *longopts, int *longind);
extern int getopt_long_only (int argc, char *const *argv,
@@ -128,11 +140,16 @@ extern int _getopt_internal (int argc, char *const *argv,
const struct option *longopts, int *longind,
int long_only);
#else /* not __STDC__ */
+
+#ifdef REALLY_NEED_PLAIN_GETOPT
extern int getopt ();
+#endif /* REALLY_NEED_PLAIN_GETOPT */
+
extern int getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal ();
+
#endif /* __STDC__ */
#ifdef __cplusplus