bug-gnulib
[Top][All Lists]
Advanced

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

Re: sys_ioctl, sys_select: fix link errors


From: Bruno Haible
Subject: Re: sys_ioctl, sys_select: fix link errors
Date: Mon, 29 Mar 2010 01:30:51 +0100
User-agent: KMail/1.9.9

Hi Ludo,

> >     * lib/sys_ioctl.in.h (ioctl): Fix declaration idiom.
> 
> This patch appears to break Inetutils bootstrapping:
> 
>   http://hydra.nixos.org/build/335490

Thanks for the quick report. This should fix it. The fix is modeled after the
gettimeofday, forkpty, openpty wrappers by Eric.


2010-03-28  Bruno Haible  <address@hidden>

        Fix ioctl's protoype on glibc systems.
        * lib/sys_ioctl.in.h (ioctl): If REPLACE_IOCTL is 1, use a wrapper. Use
        _GL_CXXALIAS_SYS, not _GL_CXXALIAS_SYS_CAST.
        * lib/ioctl.c (rpl_ioctl) [HAVE_IOCTL]: New wrapper.
        * modules/ioctl (configure.ac): Test whether ioctl has the POSIX
        signature. If not, arrange to replace the ioctl function.
        * m4/sys_ioctl_h.m4 (gl_SYS_IOCTL_H_DEFAULTS): Initialize
        REPLACE_IOCTL.
        * modules/sys_ioctl (Makefile.am): Substitute REPLACE_IOCTL.
        * doc/posix-functions/ioctl.texi: Mention the glibc problem.
        Reported by Ludovic Courtès <address@hidden>.

--- doc/posix-functions/ioctl.texi.orig Mon Mar 29 02:22:24 2010
+++ doc/posix-functions/ioctl.texi      Mon Mar 29 02:22:13 2010
@@ -12,6 +12,9 @@
 On Windows platforms (excluding Cygwin), @code{ioctl} is called
 @code{ioctlsocket}, and error codes for this function are not placed in
 @code{errno}, and @code{WSAGetLastError} must be used instead.
address@hidden
+On glibc platforms, the second parameter is of type @code{unsigned long}
+rather than @code{int}.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- lib/ioctl.c.orig    Mon Mar 29 02:22:24 2010
+++ lib/ioctl.c Mon Mar 29 01:51:48 2010
@@ -23,12 +23,31 @@
 
 #include <stdarg.h>
 
-#define WIN32_LEAN_AND_MEAN
+#if HAVE_IOCTL
+
+/* Provide a wrapper with the POSIX prototype.  */
+# undef ioctl
+int
+rpl_ioctl (int fd, int request, ... /* {void *,char *} arg */)
+{
+  void *buf;
+  va_list args;
+
+  va_start (args, request);
+  buf = va_arg (args, void *);
+  va_end (args);
+
+  return ioctl (fd, request, buf);
+}
+
+#else /* mingw */
+
+# define WIN32_LEAN_AND_MEAN
 /* Get winsock2.h. */
-#include <sys/socket.h>
+# include <sys/socket.h>
 
 /* Get set_winsock_errno, FD_TO_SOCKET etc. */
-#include "w32sock.h"
+# include "w32sock.h"
 
 int
 rpl_ioctl (int fd, int req, ...)
@@ -49,3 +68,5 @@
 
   return r;
 }
+
+#endif
--- lib/sys_ioctl.in.h.orig     Mon Mar 29 02:22:24 2010
+++ lib/sys_ioctl.in.h  Mon Mar 29 02:17:22 2010
@@ -44,7 +44,7 @@
 /* Declare overridden functions.  */
 
 #if @GNULIB_IOCTL@
-# if @SYS_IOCTL_H_HAVE_WINSOCK2_H@
+# if @SYS_IOCTL_H_HAVE_WINSOCK2_H@ || @REPLACE_IOCTL@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef ioctl
 #   define ioctl rpl_ioctl
@@ -56,10 +56,8 @@
 # else
 _GL_FUNCDECL_SYS (ioctl, int,
                   (int fd, int request, ... /* {void *,char *} arg */));
-/* Need to cast, because on glibc systems, the second parameter is
-                                unsigned long int request.  */
-_GL_CXXALIAS_SYS_CAST (ioctl, int,
-                       (int fd, int request, ... /* {void *,char *} arg */));
+_GL_CXXALIAS_SYS (ioctl, int,
+                  (int fd, int request, ... /* {void *,char *} arg */));
 # endif
 _GL_CXXALIASWARN (ioctl);
 #elif @SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
--- m4/sys_ioctl_h.m4.orig      Mon Mar 29 02:22:24 2010
+++ m4/sys_ioctl_h.m4   Mon Mar 29 02:13:02 2010
@@ -1,4 +1,4 @@
-# sys_ioctl_h.m4 serial 7
+# sys_ioctl_h.m4 serial 8
 dnl Copyright (C) 2008-2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -67,4 +67,5 @@
   SYS_IOCTL_H_HAVE_WINSOCK2_H=0; AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H])
   SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0;
                         AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS])
+  REPLACE_IOCTL=0;      AC_SUBST([REPLACE_IOCTL])
 ])
--- modules/ioctl.orig  Mon Mar 29 02:22:24 2010
+++ modules/ioctl       Mon Mar 29 02:11:56 2010
@@ -11,6 +11,7 @@
 errno
 
 configure.ac:
+AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
 AC_REQUIRE([gl_HEADER_SYS_SOCKET])
 if test "$ac_cv_header_winsock2_h" = yes; then
   dnl Even if the 'socket' module is not used here, another part of the
@@ -18,6 +19,26 @@
   dnl sockets to the ioctl() function. So enable the support for sockets.
   AC_LIBOBJ([ioctl])
   gl_REPLACE_SYS_IOCTL_H
+else
+  AC_CHECK_FUNCS([ioctl])
+  dnl On glibc systems, the second parameter is 'unsigned long int request',
+  dnl not 'int request'. We cannot simply cast the function pointer, but
+  dnl instead need a wrapper.
+  AC_CACHE_CHECK([for ioctl with POSIX signature],
+    [gl_cv_func_ioctl_posix_signature],
+    [AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[#include <sys/ioctl.h>]],
+          [[extern int ioctl (int, int, ...);]])
+       ],
+       [gl_cv_func_ioctl_posix_signature=yes],
+       [gl_cv_func_ioctl_posix_signature=no])
+    ])
+  if test $gl_cv_func_ioctl_posix_signature != yes; then
+    REPLACE_IOCTL=1
+    AC_LIBOBJ([ioctl])
+    gl_REPLACE_SYS_IOCTL_H
+  fi
 fi
 gl_SYS_IOCTL_MODULE_INDICATOR([ioctl])
 
--- modules/sys_ioctl.orig      Mon Mar 29 02:22:24 2010
+++ modules/sys_ioctl   Mon Mar 29 02:13:47 2010
@@ -31,6 +31,7 @@
              -e 's|@''GNULIB_IOCTL''@|$(GNULIB_IOCTL)|g' \
              -e 
's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H)|g' \
              -e 
's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g'
 \
+             -e 's|@''REPLACE_IOCTL''@|$(REPLACE_IOCTL)|g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
              < $(srcdir)/sys_ioctl.in.h; \




reply via email to

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