xref: /netbsd-src/external/gpl3/gdb/dist/gnulib/import/pipe.c (revision 4b169a6ba595ae283ca507b26b15fdff40495b1c)
1*4b169a6bSchristos /* Create a pipe.
2*4b169a6bSchristos    Copyright (C) 2009-2022 Free Software Foundation, Inc.
3*4b169a6bSchristos 
4*4b169a6bSchristos    This file is free software: you can redistribute it and/or modify
5*4b169a6bSchristos    it under the terms of the GNU Lesser General Public License as
6*4b169a6bSchristos    published by the Free Software Foundation; either version 2.1 of the
7*4b169a6bSchristos    License, or (at your option) any later version.
8*4b169a6bSchristos 
9*4b169a6bSchristos    This file is distributed in the hope that it will be useful,
10*4b169a6bSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
11*4b169a6bSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*4b169a6bSchristos    GNU Lesser General Public License for more details.
13*4b169a6bSchristos 
14*4b169a6bSchristos    You should have received a copy of the GNU Lesser General Public License
15*4b169a6bSchristos    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
16*4b169a6bSchristos 
17*4b169a6bSchristos #include <config.h>
18*4b169a6bSchristos 
19*4b169a6bSchristos /* Specification.  */
20*4b169a6bSchristos #include <unistd.h>
21*4b169a6bSchristos 
22*4b169a6bSchristos #if defined _WIN32 && ! defined __CYGWIN__
23*4b169a6bSchristos /* Native Windows API.  */
24*4b169a6bSchristos 
25*4b169a6bSchristos /* Get _pipe().  */
26*4b169a6bSchristos # include <io.h>
27*4b169a6bSchristos 
28*4b169a6bSchristos /* Get _O_BINARY.  */
29*4b169a6bSchristos # include <fcntl.h>
30*4b169a6bSchristos 
31*4b169a6bSchristos int
pipe(int fd[2])32*4b169a6bSchristos pipe (int fd[2])
33*4b169a6bSchristos {
34*4b169a6bSchristos   /* Mingw changes fd to {-1,-1} on failure, but this violates
35*4b169a6bSchristos      http://austingroupbugs.net/view.php?id=467 */
36*4b169a6bSchristos   int tmp[2];
37*4b169a6bSchristos   int result = _pipe (tmp, 4096, _O_BINARY);
38*4b169a6bSchristos   if (!result)
39*4b169a6bSchristos     {
40*4b169a6bSchristos       fd[0] = tmp[0];
41*4b169a6bSchristos       fd[1] = tmp[1];
42*4b169a6bSchristos     }
43*4b169a6bSchristos   return result;
44*4b169a6bSchristos }
45*4b169a6bSchristos 
46*4b169a6bSchristos #else
47*4b169a6bSchristos 
48*4b169a6bSchristos # error "This platform lacks a pipe function, and Gnulib doesn't provide a replacement. This is a bug in Gnulib."
49*4b169a6bSchristos 
50*4b169a6bSchristos #endif
51