Release 990226.
[wine/gsoc-2012-control.git] / scheduler / pipe.c
bloba7b4889900a174db7f4aa5d299c994ad5011f397
1 /*
2 * Win32 pipes
4 * Copyright 1998 Alexandre Julliard
5 */
7 #include <assert.h>
8 #include "winerror.h"
9 #include "k32obj.h"
10 #include "process.h"
11 #include "thread.h"
12 #include "heap.h"
13 #include "server/request.h"
14 #include "server.h"
16 typedef struct _PIPE
18 K32OBJ header;
19 } PIPE;
22 /***********************************************************************
23 * CreatePipe (KERNEL32.170)
25 BOOL WINAPI CreatePipe( PHANDLE hReadPipe, PHANDLE hWritePipe,
26 LPSECURITY_ATTRIBUTES sa, DWORD size )
28 struct create_pipe_request req;
29 struct create_pipe_reply reply;
30 PIPE *read_pipe, *write_pipe;
31 int len;
33 req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
34 CLIENT_SendRequest( REQ_CREATE_PIPE, -1, 1, &req, sizeof(req) );
35 if (CLIENT_WaitReply( &len, NULL, 1, &reply, sizeof(reply) ) != ERROR_SUCCESS)
36 return FALSE;
38 SYSTEM_LOCK();
39 if (!(read_pipe = (PIPE *)K32OBJ_Create( K32OBJ_PIPE, sizeof(*read_pipe),
40 NULL, reply.handle_read,
41 STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_READ,
42 sa, hReadPipe )))
44 CLIENT_CloseHandle( reply.handle_write );
45 /* handle_read already closed by K32OBJ_Create */
46 SYSTEM_UNLOCK();
47 return FALSE;
49 K32OBJ_DecCount( &read_pipe->header );
50 if (!(write_pipe = (PIPE *)K32OBJ_Create( K32OBJ_PIPE, sizeof(*write_pipe),
51 NULL, reply.handle_write,
52 STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_WRITE,
53 sa, hWritePipe )))
55 CloseHandle( *hReadPipe );
56 *hReadPipe = INVALID_HANDLE_VALUE;
57 SYSTEM_UNLOCK();
58 return FALSE;
60 /* everything OK */
61 K32OBJ_DecCount( &write_pipe->header );
62 SetLastError(0); /* FIXME */
63 SYSTEM_UNLOCK();
64 return TRUE;