summaryrefslogtreecommitdiff
path: root/lib/pipe.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2010-12-11 03:03:05 +0100
committerBruno Haible <bruno@clisp.org>2010-12-11 03:03:05 +0100
commit1594aaeaab7775c1de2d6fcaeaa002d621f6dae3 (patch)
treebd254b7803bcfcc9a5d897b54f55fbfa125f2c04 /lib/pipe.c
parent8ecf1d24ee3fae764eaed003e615269787aeb8e3 (diff)
downloadgnulib-1594aaeaab7775c1de2d6fcaeaa002d621f6dae3.tar.gz
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.
Diffstat (limited to 'lib/pipe.c')
-rw-r--r--lib/pipe.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/pipe.c b/lib/pipe.c
new file mode 100644
index 0000000000..e002ad2e60
--- /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