define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / compiler / clib / pipe.c
blob43589d60f7027b4d7c4777bc4485106287a563d3
1 /*
2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/dos.h>
7 #include <proto/exec.h>
8 #include <exec/exec.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <fcntl.h>
14 #include "__errno.h"
15 #include "__open.h"
17 /*****************************************************************************
19 NAME */
21 int pipe(
23 /* SYNOPSIS */
24 int *pipedes)
26 /* FUNCTION
28 INPUTS
30 RESULT
32 NOTES
34 EXAMPLE
36 BUGS
38 SEE ALSO
40 INTERNALS
42 ******************************************************************************/
44 BPTR reader, writer;
45 fcb *rfcb, *wfcb;
46 fdesc *rdesc, *wdesc;
48 if (!pipedes)
50 errno = EFAULT;
52 return -1;
55 if (
56 (rfcb = AllocVec(sizeof(fcb), MEMF_ANY | MEMF_CLEAR)) == NULL ||
57 (rdesc = __alloc_fdesc()) == NULL ||
58 (wfcb = AllocVec(sizeof(fcb), MEMF_ANY | MEMF_CLEAR)) == NULL ||
59 (wdesc = __alloc_fdesc()) == NULL
62 if(rfcb)
63 FreeVec(rfcb);
64 if(rdesc)
65 __free_fdesc(rdesc);
66 if(wfcb)
67 FreeVec(wfcb);
68 if(wdesc)
69 __free_fdesc(wdesc);
70 errno = ENOMEM;
71 return -1;
74 if (Pipe("XPIPE:", &reader, &writer) != DOSTRUE) {
75 errno = IoErr2errno(IoErr());
76 __free_fdesc(rdesc);
77 __free_fdesc(wdesc);
78 return -1;
81 pipedes[0] = __getfdslot(__getfirstfd(0));
82 rdesc->fdflags = 0;
83 rdesc->fcb = rfcb;
84 rdesc->fcb->fh = reader;
85 rdesc->fcb->flags = O_RDONLY;
86 rdesc->fcb->opencount = 1;
87 __setfdesc(pipedes[0], rdesc);
89 pipedes[1] = __getfdslot(__getfirstfd(pipedes[0]));
90 wdesc->fdflags = 0;
91 wdesc->fcb = wfcb;
92 wdesc->fcb->fh = writer;
93 wdesc->fcb->flags = O_WRONLY;
94 wdesc->fcb->opencount = 1;
95 __setfdesc(pipedes[1], wdesc);
97 return 0;