add a missing section header table index conversion
[tangerine.git] / compiler / clib / pipe.c
blobdab1f0fa0a491e85a287b5b384527f78e269def8
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/dos.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <fcntl.h>
12 #include "__errno.h"
13 #include "__open.h"
15 int pipe(int *pipedes)
17 BPTR reader, writer;
18 fdesc *rdesc, *wdesc;
20 if (!pipedes)
22 errno = EFAULT;
24 return -1;
27 if ((rdesc = malloc(sizeof(fdesc))) == NULL)
28 return -1;
29 if ((wdesc = malloc(sizeof(fdesc))) == NULL) {
30 free(rdesc);
31 return -1;
34 if (Pipe("PIPEFS:", &reader, &writer) != DOSTRUE) {
35 errno = IoErr2errno(IoErr());
36 free(rdesc);
37 free(wdesc);
38 return -1;
41 pipedes[0] = __getfdslot(__getfirstfd(0));
42 rdesc->fh = reader;
43 rdesc->flags = O_RDONLY;
44 rdesc->opencount = 1;
45 __setfdesc(pipedes[0], rdesc);
47 pipedes[1] = __getfdslot(__getfirstfd(pipedes[0]));
48 wdesc->fh = writer;
49 wdesc->flags = O_WRONLY;
50 wdesc->opencount = 1;
51 __setfdesc(pipedes[1], wdesc);
53 return 0;