diff options
-rw-r--r-- | lib/getopt.c | 44 | ||||
-rw-r--r-- | lib/getopt.h | 53 | ||||
-rw-r--r-- | lib/getopt1.c | 11 | ||||
-rw-r--r-- | zebra/misc_null.c | 3 |
4 files changed, 45 insertions, 66 deletions
diff --git a/lib/getopt.c b/lib/getopt.c index 001e39b6..7ea02a63 100644 --- a/lib/getopt.c +++ b/lib/getopt.c @@ -34,15 +34,7 @@ # include <config.h>
#endif
-#if !defined __STDC__ || !__STDC__
-/* This is a separate conditional since some stdc systems
- reject `defined (const)'. */
-# ifndef const
-# define const
-# endif
-#endif
-
-#include "ansidecl.h"
+#include "zebra.h"
#include <stdio.h>
/* Comment out all this code if we are using the GNU C Library, and are not
@@ -200,7 +192,8 @@ static char *posixly_correct; in GCC. */
# include <string.h>
# define my_index strchr
-#else
+
+#else /* not __GNU_LIBRARY__ */
# if HAVE_STRING_H
# include <string.h>
@@ -213,9 +206,9 @@ static char *posixly_correct; /* Avoid depending on library functions or files
whose names are inconsistent. */
-#if HAVE_STDLIB_H && HAVE_DECL_GETENV
+# if HAVE_STDLIB_H && HAVE_DECL_GETENV
# include <stdlib.h>
-#elif !defined(getenv)
+# elif !defined(getenv)
# ifdef __cplusplus
extern "C" {
# endif /* __cplusplus */
@@ -223,7 +216,7 @@ extern char *getenv (const char *); # ifdef __cplusplus
}
# endif /* __cplusplus */
-#endif
+# endif /* HAVE_STDLIB_H && HAVE_DECL_GETENV */
static char *
my_index (const char *str, int chr)
@@ -239,17 +232,17 @@ my_index (const char *str, int chr) /* If using GCC, we can safely declare strlen this way.
If not using GCC, it is ok not to declare it. */
-#ifdef __GNUC__
+# ifdef __GNUC__
/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
That was relevant to code that was here before. */
-# if (!defined __STDC__ || !__STDC__) && !defined strlen
+# if (!defined __STDC__ || !__STDC__) && !defined strlen
/* gcc with -traditional declares the built-in strlen to return int,
and has done so at least since version 2.4.5. -- rms. */
extern int strlen (const char *);
-# endif /* not __STDC__ */
-#endif /* __GNUC__ */
+# endif /* not __STDC__ */
+# endif /* __GNUC__ */
-#endif /* not __GNU_LIBRARY__ */
+#endif /* not __GNU_LIBRARY__ */
/* Handle permutation of arguments. */
@@ -309,10 +302,6 @@ text_set_element (__libc_subinit, store_args_and_env); `first_nonopt' and `last_nonopt' are relocated so that they describe
the new indices of the non-options in ARGV after they are moved. */
-#if defined __STDC__ && __STDC__
-static void exchange (char **);
-#endif
-
static void
exchange (char **argv)
{
@@ -394,12 +383,9 @@ exchange (char **argv) /* Initialize the internal data when the first call is made. */
-#if defined __STDC__ && __STDC__
-static const char *_getopt_initialize (int, char *const *, const char *);
-#endif
static const char *
-_getopt_initialize (int argc ATTRIBUTE_UNUSED,
- char *const *argv ATTRIBUTE_UNUSED,
+_getopt_initialize (int argc,
+ char *const *argv,
const char *optstring)
{
/* Start processing options with ARGV-element 1 (since ARGV-element 0
@@ -970,6 +956,8 @@ _getopt_internal (int argc, char *const *argv, const char *optstring, }
}
+#ifdef REALLY_NEED_PLAIN_GETOPT
+
int
getopt (int argc, char *const *argv, const char *optstring)
{
@@ -979,6 +967,8 @@ getopt (int argc, char *const *argv, const char *optstring) 0);
}
+#endif /* REALLY_NEED_PLAIN_GETOPT */
+
#endif /* Not ELIDE_CODE. */
#ifdef TEST
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
}
diff --git a/lib/getopt1.c b/lib/getopt1.c index 166abac5..a8ec9e98 100644 --- a/lib/getopt1.c +++ b/lib/getopt1.c @@ -24,18 +24,11 @@ #include <config.h>
#endif
-#if !defined __STDC__ || !__STDC__
-/* This is a separate conditional since some stdc systems
- reject `defined (const)'. */
-#ifndef const
-#define const
-#endif
-#endif
+#include "zebra.h"
+#include "getopt.h"
#include <stdio.h>
-#include "getopt.h"
-
/* Comment out all this code if we are using the GNU C Library, and are not
actually compiling the library itself. This code is part of the GNU C
Library, but also included in many other GNU distributions. Compiling
diff --git a/zebra/misc_null.c b/zebra/misc_null.c index d1d17f71..f0269ec2 100644 --- a/zebra/misc_null.c +++ b/zebra/misc_null.c @@ -5,8 +5,7 @@ #include "zebra/irdp.h" #include "zebra/interface.h" -extern void ifstat_update_proc (void) ; -extern void ifstat_update_proc (void) { return; } ; +void ifstat_update_proc (void) { return; } ; #pragma weak rtadv_config_write = ifstat_update_proc #pragma weak irdp_config_write = ifstat_update_proc |