Use free Windows DDK and compile with latest MinGW releases.
[reactos.git] / reactos / lib / msvcrt / io / pipe.c
1 /* $Id: pipe.c,v 1.3 2002/09/07 15:12:32 chorns Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/crtdll/io/pipe.c
6 * PURPOSE: Creates a pipe
7 * PROGRAMER: DJ Delorie
8 * UPDATE HISTORY:
9 * 28/12/98: Appropriated for Reactos
10 */
11 #include <msvcrti.h>
12
13
14 int _pipe(int _fildes[2], unsigned int size, int mode )
15 {
16 HANDLE hReadPipe, hWritePipe;
17 SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
18
19 if (mode & O_NOINHERIT)
20 sa.bInheritHandle = FALSE;
21
22 if (!CreatePipe(&hReadPipe,&hWritePipe,&sa,size))
23 return -1;
24
25 if ((_fildes[0] = __fileno_alloc(hReadPipe, mode)) < 0)
26 {
27 CloseHandle(hReadPipe);
28 CloseHandle(hWritePipe);
29 __set_errno(EMFILE);
30 return -1;
31 }
32
33 if ((_fildes[1] = __fileno_alloc(hWritePipe, mode)) < 0)
34 {
35 __fileno_close(_fildes[0]);
36 CloseHandle(hReadPipe);
37 CloseHandle(hWritePipe);
38 __set_errno(EMFILE);
39 return -1;
40 }
41 return 0;
42 }