changeset 10615:be40ec1f7b03

New module 'sys_ioctl'.
author Bruno Haible <bruno@clisp.org>
date Fri, 10 Oct 2008 04:25:28 +0200
parents c5d07fcd0933
children df8ab5d7dc3e
files ChangeLog doc/glibc-headers/sys_ioctl.texi lib/sys_ioctl.in.h m4/sys_ioctl_h.m4 modules/sys_ioctl
diffstat 5 files changed, 187 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-10-09  Bruno Haible  <bruno@clisp.org>
+
+	New module 'sys_ioctl'.
+	* lib/sys_ioctl.in.h: New file.
+	* m4/sys_ioctl_h.m4: New file.
+	* modules/sys_ioctl: New file.
+	* doc/glibc-headers/sys_ioctl.texi: Mention the new module.
+
 2008-10-09  Bruno Haible  <bruno@clisp.org>
 
 	* lib/sys_socket.in.h (ioctl): Make signature POSIX compliant.
--- a/doc/glibc-headers/sys_ioctl.texi
+++ b/doc/glibc-headers/sys_ioctl.texi
@@ -16,14 +16,10 @@
 @uref{http://www.kernel.org/doc/man-pages/online/pages/man2/ioctl.2.html,,man ioctl}.
 @end itemize
 
-Gnulib module: ---
+Gnulib module: sys_ioctl
 
 Portability problems fixed by Gnulib:
 @itemize
-@end itemize
-
-Portability problems not fixed by Gnulib:
-@itemize
 @item
 This header file is missing on some platforms:
 mingw.
@@ -31,3 +27,7 @@
 This header file does not declare the @code{ioctl} function on some platforms:
 AIX 5.1, Solaris 10.
 @end itemize
+
+Portability problems not fixed by Gnulib:
+@itemize
+@end itemize
new file mode 100644
--- /dev/null
+++ b/lib/sys_ioctl.in.h
@@ -0,0 +1,68 @@
+/* Substitute for and wrapper around <sys/ioctl.h>.
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#ifndef _GL_SYS_IOCTL_H
+
+@PRAGMA_SYSTEM_HEADER@
+
+/* The include_next requires a split double-inclusion guard.  */
+#if @HAVE_SYS_IOCTL_H@
+# @INCLUDE_NEXT@ @NEXT_SYS_IOCTL_H@
+#endif
+
+#ifndef _GL_SYS_IOCTL_H
+#define _GL_SYS_IOCTL_H
+
+/* AIX 5.1 and Solaris 10 declare ioctl() in <unistd.h> and in <stropts.h>,
+   but not in <sys/ioctl.h>.  */
+#include <unistd.h>
+
+/* The definition of GL_LINK_WARNING is copied here.  */
+
+
+/* Declare overridden functions.  */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#if @GNULIB_IOCTL@
+# if @SYS_IOCTL_H_HAVE_WINSOCK2_H@
+#  undef ioctl
+#  define ioctl rpl_ioctl
+extern int ioctl (int fd, int request, ... /* {void *,char *} arg */);
+# endif
+#elif @SYS_IOCTL_H_HAVE_WINSOCK2_H@
+# undef ioctl
+# define ioctl ioctl_used_without_requesting_gnulib_module_ioctl
+#elif defined GNULIB_POSIXCHECK
+# undef ioctl
+# define ioctl(f,c,a) \
+    (GL_LINK_WARNING ("ioctl does not portably work on sockets - " \
+                      "use gnulib module ioctl for portability"), \
+     ioctl (f, c, a))
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _GL_SYS_IOCTL_H */
+#endif /* _GL_SYS_IOCTL_H */
new file mode 100644
--- /dev/null
+++ b/m4/sys_ioctl_h.m4
@@ -0,0 +1,60 @@
+# sys_ioctl_h.m4 serial 1
+dnl Copyright (C) 2008 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Bruno Haible.
+
+AC_DEFUN([gl_SYS_IOCTL_H],
+[
+  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
+  dnl once only, before all statements that occur in other macros.
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+
+  AC_CHECK_HEADERS_ONCE([sys/ioctl.h])
+  if test $ac_cv_header_sys_ioctl_h = yes; then
+    HAVE_SYS_IOCTL_H=1
+    dnl Test whether <sys/ioctl.h> declares ioctl(), or whether some other
+    dnl header file, such as <unistd.h> or <stropts.h>, is needed for that.
+    AC_CACHE_CHECK([whether <sys/ioctl.h> declares ioctl],
+      [gl_cv_decl_ioctl_in_sys_ioctl_h],
+      [AC_CHECK_DECL([ioctl],
+         [gl_cv_decl_ioctl_in_sys_ioctl_h=yes],
+         [gl_cv_decl_ioctl_in_sys_ioctl_h=no],
+         [#include <sys/ioctl.h>])
+      ])
+    if test $gl_cv_decl_ioctl_in_sys_ioctl_h != yes; then
+      SYS_IOCTL_H='sys/ioctl.h'
+    fi
+  else
+    HAVE_SYS_IOCTL_H=0
+    SYS_IOCTL_H='sys/ioctl.h'
+  fi
+  AC_SUBST([HAVE_SYS_IOCTL_H])
+  dnl Execute this unconditionally, because SYS_IOCTL_H may be set by other
+  dnl modules, after this code is executed.
+  gl_CHECK_NEXT_HEADERS([sys/ioctl.h])
+])
+
+dnl Unconditionally enables the replacement of <sys/ioctl.h>.
+AC_DEFUN([gl_REPLACE_SYS_IOCTL_H],
+[
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+  SYS_IOCTL_H='sys/ioctl.h'
+])
+
+AC_DEFUN([gl_SYS_IOCTL_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+  GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
+])
+
+AC_DEFUN([gl_SYS_IOCTL_H_DEFAULTS],
+[
+  GNULIB_IOCTL=0;         AC_SUBST([GNULIB_IOCTL])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  SYS_IOCTL_H_HAVE_WINSOCK2_H=0; AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H])
+  SYS_IOCTL_H='';                AC_SUBST([SYS_IOCTL_H])
+])
new file mode 100644
--- /dev/null
+++ b/modules/sys_ioctl
@@ -0,0 +1,46 @@
+Description:
+A <sys/ioctl.h> for systems with missing declarations.
+
+Files:
+lib/sys_ioctl.in.h
+m4/sys_ioctl_h.m4
+
+Depends-on:
+include_next
+link-warning
+unistd
+
+configure.ac:
+gl_SYS_IOCTL_H
+AC_PROG_MKDIR_P
+
+Makefile.am:
+BUILT_SOURCES += $(SYS_IOCTL_H)
+
+# We need the following in order to create <sys/ioctl.h> when the system
+# does not have a complete one.
+sys/ioctl.h: sys_ioctl.in.h
+	@MKDIR_P@ sys
+	rm -f $@-t $@
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''HAVE_SYS_IOCTL_H''@|$(HAVE_SYS_IOCTL_H)|g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''NEXT_SYS_IOCTL_H''@|$(NEXT_SYS_IOCTL_H)|g' \
+	      -e 's|@''GNULIB_IOCTL''@|$(GNULIB_IOCTL)|g' \
+	      -e 's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H)|g' \
+	      -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
+	      < $(srcdir)/sys_ioctl.in.h; \
+	} > $@-t
+	mv $@-t $@
+MOSTLYCLEANFILES += sys/ioctl.h sys/ioctl.h-t
+MOSTLYCLEANDIRS += sys
+
+Include:
+#include <sys/ioctl.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all