* Automatic generation of varargs stub for a function can now be disabled by
[AROS.git] / test / pipe.c
blobb3150c8257472a3a9df01b6f9236cb23fead7928
1 #include <proto/exec.h>
2 #include <proto/alib.h>
3 #include <proto/dos.h>
4 #include <dos/filesystem.h>
5 #include <dos/dos.h>
6 #include <exec/memory.h>
8 #include <assert.h>
10 static struct IOFileSys *CreateIOFS(ULONG type, struct MsgPort *port, struct FileHandle *fh)
12 struct IOFileSys *iofs = (struct IOFileSys *)AllocMem(sizeof(struct IOFileSys), MEMF_PUBLIC|MEMF_CLEAR);
14 if (iofs == NULL)
15 return NULL;
17 iofs->IOFS.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
18 iofs->IOFS.io_Message.mn_ReplyPort = port;
19 iofs->IOFS.io_Message.mn_Length = sizeof(struct IOFileSys);
20 iofs->IOFS.io_Command = type;
21 iofs->IOFS.io_Flags = 0;
22 iofs->IOFS.io_Device = fh->fh_Device;
23 iofs->IOFS.io_Unit = fh->fh_Unit;
25 return iofs;
28 static BPTR DupFH(BPTR fh, LONG mode)
30 BPTR ret = NULL;
32 if (fh)
34 BPTR olddir = CurrentDir(fh);
35 ret = Open("", mode);
37 CurrentDir(olddir);
40 return ret;
43 int main(void)
45 struct FileHandle *fhin, *fhout;
46 struct MsgPort *port;
47 struct IOFileSys *iofs;
49 fhin = Open("PIPEFS:__UNNAMED__", FMF_READ|FMF_NONBLOCK);
50 fhout = DupFH(fhin, FMF_WRITE);
51 assert(fhin!=NULL && fhout!=NULL);
52 ChangeMode(CHANGE_FH, fhin, FMF_READ);
54 port = CreatePort(NULL, 0);
55 assert(port!=NULL);
57 iofs = CreateIOFS(FSA_WRITE, port, fhout);
58 iofs->io_Union.io_WRITE.io_Buffer = "Test\n";
59 iofs->io_Union.io_WRITE.io_Length = 5;
61 SendIO(&iofs->IOFS);
63 Close(fhin);
65 iofs = CreateIOFS(FSA_WRITE, port, fhout);
66 iofs->io_Union.io_WRITE.io_Buffer = "Test\n";
67 iofs->io_Union.io_WRITE.io_Length = 5;
69 SendIO(&iofs->IOFS);
71 Close(fhout);
72 DeletePort(port);
74 return 0;