Autodoc corrections
[cake.git] / compiler / clib / pipe.c
blob1f558be175887bb005b2319c7b7b79346c4fdd12
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 /*****************************************************************************
17 NAME */
19 int pipe(
21 /* SYNOPSIS */
22 int *pipedes)
24 /* FUNCTION
26 INPUTS
28 RESULT
30 NOTES
32 EXAMPLE
34 BUGS
36 SEE ALSO
38 INTERNALS
40 ******************************************************************************/
42 BPTR reader, writer;
43 fdesc *rdesc, *wdesc;
45 if (!pipedes)
47 errno = EFAULT;
49 return -1;
52 if ((rdesc = malloc(sizeof(fdesc))) == NULL)
53 return -1;
54 if ((wdesc = malloc(sizeof(fdesc))) == NULL) {
55 free(rdesc);
56 return -1;
59 if (Pipe("XPIPE:", &reader, &writer) != DOSTRUE) {
60 errno = IoErr2errno(IoErr());
61 free(rdesc);
62 free(wdesc);
63 return -1;
66 pipedes[0] = __getfdslot(__getfirstfd(0));
67 rdesc->fh = reader;
68 rdesc->flags = O_RDONLY;
69 rdesc->opencount = 1;
70 __setfdesc(pipedes[0], rdesc);
72 pipedes[1] = __getfdslot(__getfirstfd(pipedes[0]));
73 wdesc->fh = writer;
74 wdesc->flags = O_WRONLY;
75 wdesc->opencount = 1;
76 __setfdesc(pipedes[1], wdesc);
78 return 0;