# HG changeset patch # User Bruno Haible # Date 1292032985 -3600 # Node ID 29a6861886518bf74058a8405a5e8177d5237d98 # Parent 5be0c314f2f87fb7fadd125136381b7998b137c3 pipe-posix: Make it work in C++ mode. * lib/unistd.in.h: Don't include , 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. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2010-12-10 Bruno Haible + + pipe-posix: Make it work in C++ mode. + * lib/unistd.in.h: Don't include , 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 Rename module 'pipe' to 'spawn-pipe'. diff --git a/lib/pipe.c b/lib/pipe.c new file mode 100644 --- /dev/null +++ b/lib/pipe.c @@ -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 + +/* Specification. */ +#include + +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +/* Native Woe32 API. */ + +/* Get _pipe(). */ +# include + +/* Get _O_BINARY. */ +# include + +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 diff --git a/lib/unistd.in.h b/lib/unistd.in.h --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -82,14 +82,10 @@ # include #endif -/* mingw declares getcwd in , not in . It also provides - _pipe in , but that requires _O_BINARY from . */ -#if ((@GNULIB_GETCWD@ || @GNULIB_PIPE@ || defined GNULIB_POSIXCHECK) \ +/* mingw declares getcwd in , not in . */ +#if ((@GNULIB_GETCWD@ || defined GNULIB_POSIXCHECK) \ && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)) # include -# if @GNULIB_PIPE@ -# include -# endif #endif /* AIX and OSF/1 5.1 declare getdomainname in , not in . */ @@ -980,14 +976,22 @@ /* 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 --- /dev/null +++ b/m4/pipe.m4 @@ -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 +]) diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -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 @@ 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]) diff --git a/modules/pipe-posix b/modules/pipe-posix --- a/modules/pipe-posix +++ b/modules/pipe-posix @@ -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: diff --git a/modules/unistd b/modules/unistd --- a/modules/unistd +++ b/modules/unistd @@ -87,6 +87,7 @@ -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' \ diff --git a/tests/test-unistd-c++.cc b/tests/test-unistd-c++.cc --- a/tests/test-unistd-c++.cc +++ b/tests/test-unistd-c++.cc @@ -129,6 +129,10 @@ 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