Implemented the pipe() command - ready for the upcoming pipefs implementation.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3675 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2003-06-27 02:55:15 +00:00
parent 41415a1bc0
commit e59c643b47
2 changed files with 35 additions and 0 deletions
+1
View File
@@ -15,6 +15,7 @@ KernelMergeObject posix_unistd.o :
<$(SOURCE_GRIST)>lseek.c
<$(SOURCE_GRIST)>mount.c
<$(SOURCE_GRIST)>open.c
<$(SOURCE_GRIST)>pipe.c
<$(SOURCE_GRIST)>read.c
<$(SOURCE_GRIST)>sleep.c
<$(SOURCE_GRIST)>terminal.c
+34
View File
@@ -0,0 +1,34 @@
/*
** Copyright 2003, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include <OS.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
int
pipe(int streams[2])
{
// ToDo: if the thread manages to call this function during the
// the same microsecond twice, we're doomed :)
char pipeName[64];
sprintf(pipeName, "/pipe/%lx-%Ld\n", find_thread(NULL), system_time());
streams[0] = open(pipeName, O_CREAT | O_RDONLY, 0777);
if (streams[0] < 0)
return -1;
streams[1] = open(pipeName, O_WRONLY);
if (streams[1] < 0) {
close(streams[0]);
return -1;
}
return 0;
}