xref: /haiku/src/system/libroot/posix/unistd/pipe.c (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
1 /*
2  * Copyright 2003-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <OS.h>
8 
9 #include <unistd.h>
10 #include <fcntl.h>
11 #include <stdio.h>
12 
13 
14 int
15 pipe(int streams[2])
16 {
17 	bigtime_t timestamp = system_time();
18 	char pipeName[64];
19 
20 	while (system_time() <= timestamp)	// ensure we get an unused timestamp
21 		;
22 
23 	sprintf(pipeName, "/pipe/%03lx-%Ld", find_thread(NULL), system_time());
24 
25 	streams[0] = open(pipeName, O_CREAT | O_RDONLY, 0777);
26 	if (streams[0] < 0)
27 		return -1;
28 
29 	streams[1] = open(pipeName, O_WRONLY);
30 	if (streams[1] < 0) {
31 		close(streams[0]);
32 		return -1;
33 	}
34 
35 	return 0;
36 }
37