[quagga-dev 3568] Re: getopt decls considered kludgy

Vincent Jardin Vincent.Jardin at 6wind.com
Mon Aug 8 16:37:52 BST 2005


Hi all,

Do we still need to keep a getopt into libzebra ? As far as I know, it 
is on all BSDs's libc and Linux's glibc. What's about Solaris ?

Regards,
  Vincent

Greg Troxel wrote:

>I hadn't tried to build quagga-head recently, and just tried and had
>several problems.  One is that getopt is declared in lib/getopt.h, but
>this did not match the POSIX.2 declaration in unistd.h on NetBSD.  I
>have made the following change to make POSIX.2 compliance the main
>path, with the notion of adding workarounds for any system which is
>STDC but does not comply with POSIX.2.  (This follows from a
>philosophy of coding to standards first and then working around
>non-standard systems, rather than adjusting to each system as it is
>encountered.)
>
>I'd like to get comments first before committing this.  If anyone has
>an 'old' system (really a system with old header files), I'd
>appreciate trying this patch.
>
>Index: lib/getopt.h
>===================================================================
>RCS file: /var/cvsroot/quagga/lib/getopt.h,v
>retrieving revision 1.4
>diff -u -r1.4 getopt.h
>--- lib/getopt.h	24 Jun 2005 01:20:25 -0000	1.4
>+++ lib/getopt.h	8 Aug 2005 15:25:54 -0000
>@@ -22,6 +22,18 @@
> #ifndef _GETOPT_H
> #define _GETOPT_H 1
> 
>+/*
>+ * The operating system may or may not provide getopt(), 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,18 @@
> #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 
>+
>+/*
>+ * 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 */
>+
> 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 +135,13 @@
> 		             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
>_______________________________________________
>Quagga-dev mailing list
>Quagga-dev at lists.quagga.net
>http://lists.quagga.net/mailman/listinfo/quagga-dev
>
>  
>




More information about the Quagga-dev mailing list