From e59c643b4753c23c9fc785039c565ad15969309f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 27 Jun 2003 02:55:15 +0000 Subject: [PATCH] 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 --- src/kernel/libroot/posix/unistd/Jamfile | 1 + src/kernel/libroot/posix/unistd/pipe.c | 34 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/kernel/libroot/posix/unistd/pipe.c diff --git a/src/kernel/libroot/posix/unistd/Jamfile b/src/kernel/libroot/posix/unistd/Jamfile index a9f0001493..a33d05df74 100644 --- a/src/kernel/libroot/posix/unistd/Jamfile +++ b/src/kernel/libroot/posix/unistd/Jamfile @@ -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 diff --git a/src/kernel/libroot/posix/unistd/pipe.c b/src/kernel/libroot/posix/unistd/pipe.c new file mode 100644 index 0000000000..51516f47ca --- /dev/null +++ b/src/kernel/libroot/posix/unistd/pipe.c @@ -0,0 +1,34 @@ +/* +** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + + +#include + +#include +#include +#include + + +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; +} +