Listtree.mcc: forward List_TestPos and Listtree_TestPos
[AROS.git] / compiler / stdc / __stdio.c
blobfb76fd7542e747a3fc9dc36e65da0390b4948652
1 /*
2 Copyright © 2010-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Setup and support code for stdio.h functionality
6 */
7 #include <exec/lists.h>
8 #include <aros/symbolsets.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <proto/alib.h>
12 #include <proto/exec.h>
13 #include <proto/dos.h>
15 #include "__stdio.h"
16 #include "__stdcio_intbase.h"
18 #define DEBUG 0
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 =
30 __STDCIO_STDIO_READ
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 =
39 __STDCIO_STDIO_WRITE
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 =
47 __STDCIO_STDIO_WRITE
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;
53 return 1;
57 static int __close_stdio(struct StdCIOIntBase *StdCIOBase)
59 FILE *stream;
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;
67 fclose(stream);
70 if (StdCIOBase->streampool)
71 DeletePool(StdCIOBase->streampool);
73 return 1;
76 ADD2OPENLIB(__init_stdio, 0)
77 ADD2CLOSELIB(__close_stdio, 0)