bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

readlink vs. getopt-gnu


From: Eric Blake
Subject: readlink vs. getopt-gnu
Date: Thu, 24 Sep 2009 17:19:54 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

I'm getting this on cygwin, when using both readlink and getopt-gnu:

In file included from /usr/include/unistd.h:4,
                 from ./unistd.h:26,
                 from ./stdlib.h:271,
                 from malloca.h:24,
                 from malloca.c:22:
/usr/include/sys/unistd.h:215: error: conflicting types for 'rpl_readlink'
./unistd.h:678: error: previous declaration of 'rpl_readlink' was here

The culprit?

./unistd.h does include_next <unistd.h>
 <unistd.h> sets a guard, then does include <sys/unistd.h>
  <sys/unistd.h> does include <optarg.h>, but picks up the gnulib version
   ./optarg.h does include <unistd.h>, and picks up the gnulib version
    ./unistd.h repeats include_next <unistd.h>
     <unistd.h> sees the guard set, and skips further processing
    ./unistd.h defines readlink
   ./optarg.h defines optarg, but fails to see the system declarations to 
properly override them
  <sys/unistd.h> tries to declare readlink, but conflicts with the gnulib 
declaration

The solution?  ./optarg.h MUST do a split inclusion guard use of include_next 
<optarg.h>, if the system has a native <optarg.h>, then not bother to include 
<unistd.h> in that case.  I could played with a change to unistd.in.h to check 
for __UNISTD_GETOPT__, similar to how stdio.in.h checks for __need_FILE, but 
since the getopt.in.h change in isolation was enough, I didn't do it for now.


From: Eric Blake <address@hidden>
Date: Thu, 24 Sep 2009 10:57:14 -0600
Subject: [PATCH] getopt: fix inclusion guards for cygwin

cygwin <unistd.h> includes <getopt.h>, but gnulib <getopt.h> includes
<unistd.h>, so system declarations were happening after gnulib
replacements, leading to multiply-defined rpl_readlink error on
cygwin 1.5.  The solution is to ensure that the system <unistd.h>
is complete prior to any of gnulib's contents, by picking up
system <getopt.h> in preference to a cycle to <unistd.h>.

* modules/getopt-posix (Depends-on): Add include-next.
(Makefile.am): Substitute more items in replacement header.
* m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Also check for native
<getopt.h>.
* lib/getopt.in.h (includes): Use split inclusion guard, and
prefer <getopt.h> over include <unistd.h> when one is present.
(option): Also override name of 'struct option'.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog            |    9 +++++++++
 lib/getopt.in.h      |   27 ++++++++++++++++++++++-----
 m4/getopt.m4         |    9 +++++++++
 modules/getopt-posix |    8 +++++++-
 4 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 697d2c1..35f84c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2009-09-24  Eric Blake  <address@hidden>

+       getopt: fix inclusion guards for cygwin
+       * modules/getopt-posix (Depends-on): Add include-next.
+       (Makefile.am): Substitute more items in replacement header.
+       * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Also check for native
+       <getopt.h>.
+       * lib/getopt.in.h (includes): Use split inclusion guard, and
+       prefer <getopt.h> over include <unistd.h> when one is present.
+       (option): Also override name of 'struct option'.
+
        same-inode: revert prior change; it is not yet ready
        * NEWS: Undo mention of this change.
        * lib/same-inode.h (same-inode.h): Undo tri-state change.
diff --git a/lib/getopt.in.h b/lib/getopt.in.h
index d2d3e6e..e23259c 100644
--- a/lib/getopt.in.h
+++ b/lib/getopt.in.h
@@ -1,5 +1,5 @@
 /* Declarations for getopt.
-   Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005,2006,2007
+   Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2005,2006,2007,2009
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.

@@ -18,6 +18,17 @@

 #ifndef _GETOPT_H

+#if __GNUC__ >= 3
address@hidden@
+#endif
+
+/* The include_next requires a split double-inclusion guard.  */
+#if @HAVE_GETOPT_H@
+# @INCLUDE_NEXT@ @NEXT_GETOPT_H@
+#endif
+
+#ifndef _GETOPT_H
+
 #ifndef __need_getopt
 # define _GETOPT_H 1
 #endif
@@ -26,14 +37,17 @@
    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
+   confusion if included after this file (if the system had <getopt.h>,
+   we have already included it).  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>
-# include <unistd.h>
+# if address@hidden@
+#  include <stdlib.h>
+#  include <stdio.h>
+#  include <unistd.h>
+# endif
 # undef __need_getopt
 # undef getopt
 # undef getopt_long
@@ -42,6 +56,7 @@
 # undef opterr
 # undef optind
 # undef optopt
+# undef option
 # define __GETOPT_CONCAT(x, y) x ## y
 # define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
 # define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
@@ -52,6 +67,7 @@
 # define opterr __GETOPT_ID (opterr)
 # define optind __GETOPT_ID (optind)
 # define optopt __GETOPT_ID (optopt)
+# define option __GETOPT_ID (option)
 #endif

 /* Standalone applications get correct prototypes for getopt_long and
@@ -223,3 +239,4 @@ extern int getopt_long_only (int ___argc, char 
*__getopt_argv_const *___argv,
 #undef __need_getopt

 #endif /* getopt.h */
+#endif /* getopt.h */
diff --git a/m4/getopt.m4 b/m4/getopt.m4
index 7443dfe..53a1a7e 100644
--- a/m4/getopt.m4
+++ b/m4/getopt.m4
@@ -54,6 +54,15 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
   dnl Persuade Solaris <unistd.h> to declare optarg, optind, opterr, optopt.
   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])

+  gl_CHECK_NEXT_HEADERS([getopt.h])
+  AC_CHECK_HEADERS_ONCE([getopt.h])
+  if test $ac_cv_header_getopt_h = yes; then
+    HAVE_GETOPT_H=1
+  else
+    HAVE_GETOPT_H=0
+  fi
+  AC_SUBST([HAVE_GETOPT_H])
+
   gl_replace_getopt=

   dnl Test whether <getopt.h> is available.
diff --git a/modules/getopt-posix b/modules/getopt-posix
index b9d2658..94932fc 100644
--- a/modules/getopt-posix
+++ b/modules/getopt-posix
@@ -12,6 +12,7 @@ Depends-on:
 gettext-h
 unistd
 extensions
+include_next

 configure.ac:
 gl_FUNC_GETOPT_POSIX
@@ -24,7 +25,12 @@ BUILT_SOURCES += $(GETOPT_H)
 getopt.h: getopt.in.h
        $(AM_V_GEN)rm -f address@hidden $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-         cat $(srcdir)/getopt.in.h; \
+         sed -e 's|@''HAVE_GETOPT_H''@|$(HAVE_GETOPT_H)|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+             -e 's|@''NEXT_GETOPT_H''@|$(NEXT_GETOPT_H)|g' \
+             -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
+             < $(srcdir)/getopt.in.h; \
        } > address@hidden && \
        mv -f address@hidden $@
 MOSTLYCLEANFILES += getopt.h getopt.h-t
-- 
1.6.1.2







reply via email to

[Prev in Thread] Current Thread [Next in Thread]