2 Copyright © 2010-2013, The AROS Development Team. All rights reserved.
5 Setup and support code for stdio.h functionality
7 #include <exec/lists.h>
8 #include <aros/symbolsets.h>
11 #include <proto/alib.h>
12 #include <proto/exec.h>
13 #include <proto/dos.h>
16 #include "__stdcio_intbase.h"
19 #include <aros/debug.h>
21 /* For each opener stdin, stdout and stderr may be different */
22 static int __init_stdio(struct StdCIOIntBase
*StdCIOBase
)
24 struct Process
*me
= (struct Process
*)FindTask(NULL
);
26 NewList((struct List
*)&StdCIOBase
->files
);
28 StdCIOBase
->intstdin
.fh
= Input();
29 StdCIOBase
->intstdin
.flags
=
31 | __STDCIO_STDIO_DONTCLOSE
32 | __STDCIO_STDIO_DONTFREE
33 | __STDCIO_STDIO_FLUSHONREAD
;
34 D(bug("[__init_stdio]: intstdin.fh=0x%x\n", StdCIOBase
->intstdin
.fh
));
35 StdCIOBase
->StdCIOBase
._stdin
= &StdCIOBase
->intstdin
;
37 StdCIOBase
->intstdout
.fh
= Output();
38 StdCIOBase
->intstdout
.flags
=
40 | __STDCIO_STDIO_DONTCLOSE
41 | __STDCIO_STDIO_DONTFREE
;
42 D(bug("[__init_stdio]: intstdout.fh=0x%x\n", StdCIOBase
->intstdout
.fh
));
43 StdCIOBase
->StdCIOBase
._stdout
= &StdCIOBase
->intstdout
;
45 StdCIOBase
->intstderr
.fh
= me
->pr_CES
? me
->pr_CES
: me
->pr_COS
;
46 StdCIOBase
->intstderr
.flags
=
48 | __STDCIO_STDIO_DONTCLOSE
49 | __STDCIO_STDIO_DONTFREE
;
50 D(bug("[__init_stdio]: intstderr.fh=0x%x\n", StdCIOBase
->intstderr
.fh
));
51 StdCIOBase
->StdCIOBase
._stderr
= &StdCIOBase
->intstderr
;
57 static int __close_stdio(struct StdCIOIntBase
*StdCIOBase
)
61 D(bug("[__close_stdio]: StdCIOBase: %x, DOSBase: %x\n", StdCIOBase
, DOSBase
));
63 ForeachNode(&StdCIOBase
->files
, stream
)
65 D(bug("[__close_stdio]: stream: %x, fh: %x\n", stream
, stream
->fh
));
66 stream
->flags
|= __STDCIO_STDIO_DONTFREE
;
70 if (StdCIOBase
->streampool
)
71 DeletePool(StdCIOBase
->streampool
);
76 ADD2OPENLIB(__init_stdio
, 0)
77 ADD2CLOSELIB(__close_stdio
, 0)