Mercurial > hg > octave-kai > gnulib-hg
changeset 13925:29a686188651
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.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 11 Dec 2010 03:03:05 +0100 |
parents | 5be0c314f2f8 |
children | b4c4a43e95e4 |
files | ChangeLog lib/pipe.c lib/unistd.in.h m4/pipe.m4 m4/unistd_h.m4 modules/pipe-posix modules/unistd tests/test-unistd-c++.cc |
diffstat | 8 files changed, 96 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +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'.
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 <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
--- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -82,14 +82,10 @@ # 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 @@ /* 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
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 +])
--- 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])
--- 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:
--- 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' \
--- 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