pipe-posix: Make it work in C++ mode.
authorBruno Haible <bruno@clisp.org>
Sat, 11 Dec 2010 02:03:05 +0000 (03:03 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 11 Dec 2010 02:03:05 +0000 (03:03 +0100)
* lib/unistd.in.h: Don't include <io.h>, <fcntl.h> for pipe.
(pipe): Use common idiom, not a macro definition.
* lib/pipe.c: New file.
* m4/pipe.m4: New file.
* modules/pipe-posix (Description): Enhance.
(Files): Add lib/pipe.c, m4/pipe.m4.
(configure.ac): Invoke gl_FUNC_PIPE.
* m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize HAVE_PIPE.
* modules/unistd (Makefile.am): Substitute HAVE_PIPE.
* tests/test-unistd-c++.cc: Check the signature of pipe.

ChangeLog
lib/pipe.c [new file with mode: 0644]
lib/unistd.in.h
m4/pipe.m4 [new file with mode: 0644]
m4/unistd_h.m4
modules/pipe-posix
modules/unistd
tests/test-unistd-c++.cc

index 137fc34..95dceb2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2010-12-10  Bruno Haible  <bruno@clisp.org>
 
+       pipe-posix: Make it work in C++ mode.
+       * lib/unistd.in.h: Don't include <io.h>, <fcntl.h> for pipe.
+       (pipe): Use common idiom, not a macro definition.
+       * lib/pipe.c: New file.
+       * m4/pipe.m4: New file.
+       * modules/pipe-posix (Description): Enhance.
+       (Files): Add lib/pipe.c, m4/pipe.m4.
+       (configure.ac): Invoke gl_FUNC_PIPE.
+       * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize HAVE_PIPE.
+       * modules/unistd (Makefile.am): Substitute HAVE_PIPE.
+       * tests/test-unistd-c++.cc: Check the signature of pipe.
+
+2010-12-10  Bruno Haible  <bruno@clisp.org>
+
        Rename module 'pipe' to 'spawn-pipe'.
        * modules/spawn-pipe: New file, renamed from modules/pipe.
        (Files, configure.ac, Makefile.am): Update.
diff --git a/lib/pipe.c b/lib/pipe.c
new file mode 100644 (file)
index 0000000..e002ad2
--- /dev/null
@@ -0,0 +1,42 @@
+/* Create a pipe.
+   Copyright (C) 2009-2010 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.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <unistd.h>
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* Native Woe32 API.  */
+
+/* Get _pipe().  */
+# include <io.h>
+
+/* Get _O_BINARY.  */
+# include <fcntl.h>
+
+int
+pipe (int fd[2])
+{
+  return _pipe (fd, 4096, _O_BINARY);
+}
+
+#else
+
+# error "This platform lacks a pipe function, and Gnulib doesn't provide a replacement. This is a bug in Gnulib."
+
+#endif
index 571afa1..6bd3264 100644 (file)
 # include <stdlib.h>
 #endif
 
-/* mingw declares getcwd in <io.h>, not in <unistd.h>.  It also provides
-   _pipe in <io.h>, but that requires _O_BINARY from <fcntl.h>.  */
-#if ((@GNULIB_GETCWD@ || @GNULIB_PIPE@ || defined GNULIB_POSIXCHECK) \
+/* mingw declares getcwd in <io.h>, not in <unistd.h>.  */
+#if ((@GNULIB_GETCWD@ || defined GNULIB_POSIXCHECK) \
      && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
 # include <io.h>
-# if @GNULIB_PIPE@
-#  include <fcntl.h>
-# endif
 #endif
 
 /* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>.  */
@@ -980,14 +976,22 @@ _GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some "
 /* Create a pipe, defaulting to O_BINARY mode.
    Store the read-end as fd[0] and the write-end as fd[1].
    Return 0 upon success, or -1 with errno set upon failure.  */
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-#  define pipe(fd) _pipe (fd, 4096, _O_BINARY)
+# if @HAVE_PIPE@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   define pipe rpl_pipe
+#  endif
+_GL_FUNCDECL_RPL (pipe, int, (int fd[2]) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (pipe, int, (int fd[2]));
+# else
+_GL_FUNCDECL_SYS (pipe, int, (int fd[2]) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_SYS (pipe, int, (int fd[2]));
 # endif
+_GL_CXXALIASWARN (pipe);
 #elif defined GNULIB_POSIXCHECK
 # undef pipe
 # if HAVE_RAW_DECL_PIPE
 _GL_WARN_ON_USE (pipe, "pipe is unportable - "
-                 "use gnulib module pipe for portability");
+                 "use gnulib module pipe-posix for portability");
 # endif
 #endif
 
diff --git a/m4/pipe.m4 b/m4/pipe.m4
new file mode 100644 (file)
index 0000000..352c2a2
--- /dev/null
@@ -0,0 +1,16 @@
+# pipe.m4 serial 1
+dnl Copyright (C) 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,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_PIPE],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+
+  AC_CHECK_FUNCS_ONCE([pipe])
+  if test $ac_cv_func_pipe != yes; then
+    HAVE_PIPE=0
+    AC_LIBOBJ([pipe])
+  fi
+])
index 0690951..31c7d00 100644 (file)
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 48
+# unistd_h.m4 serial 49
 dnl Copyright (C) 2006-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,
@@ -113,6 +113,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   HAVE_LCHOWN=1;          AC_SUBST([HAVE_LCHOWN])
   HAVE_LINK=1;            AC_SUBST([HAVE_LINK])
   HAVE_LINKAT=1;          AC_SUBST([HAVE_LINKAT])
+  HAVE_PIPE=1;            AC_SUBST([HAVE_PIPE])
   HAVE_PIPE2=1;           AC_SUBST([HAVE_PIPE2])
   HAVE_PREAD=1;           AC_SUBST([HAVE_PREAD])
   HAVE_PWRITE=1;          AC_SUBST([HAVE_PWRITE])
index 9f753db..e29f92d 100644 (file)
@@ -1,13 +1,15 @@
 Description:
-Creation of a pipe.
+pipe() function: Creation of a pipe.
 
 Files:
+lib/pipe.c
+m4/pipe.m4
 
 Depends-on:
 unistd
 
 configure.ac:
-AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+gl_FUNC_PIPE
 gl_UNISTD_MODULE_INDICATOR([pipe])
 
 Makefile.am:
index e2475dd..bf94df9 100644 (file)
@@ -87,6 +87,7 @@ unistd.h: unistd.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
              -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \
              -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \
              -e 's|@''HAVE_LINKAT''@|$(HAVE_LINKAT)|g' \
+             -e 's|@''HAVE_PIPE''@|$(HAVE_PIPE)|g' \
              -e 's|@''HAVE_PIPE2''@|$(HAVE_PIPE2)|g' \
              -e 's|@''HAVE_PREAD''@|$(HAVE_PREAD)|g' \
              -e 's|@''HAVE_PWRITE''@|$(HAVE_PWRITE)|g' \
index 2769d04..7af68b1 100644 (file)
@@ -129,6 +129,10 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::linkat, int,
 SIGNATURE_CHECK (GNULIB_NAMESPACE::lseek, off_t, (int, off_t, int));
 #endif
 
+#if GNULIB_TEST_PIPE
+SIGNATURE_CHECK (GNULIB_NAMESPACE::pipe, int, (int[2]));
+#endif
+
 #if GNULIB_TEST_PIPE2
 SIGNATURE_CHECK (GNULIB_NAMESPACE::pipe2, int, (int[2], int));
 #endif