fix config file path
[AROS.git] / compiler / clib / fflush.c
bloba053e923018229bebdd5a68e9bcc8530db1603c2
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function fflush().
6 */
8 #include "__arosc_privdata.h"
10 #include <exec/types.h>
11 #include <exec/lists.h>
12 #include <dos/dosextens.h>
13 #include <proto/exec.h>
14 #include <proto/dos.h>
15 #include <errno.h>
16 #include "__stdio.h"
17 #include "__fdesc.h"
19 /*****************************************************************************
21 NAME */
22 #include <stdio.h>
24 int fflush (
26 /* SYNOPSIS */
27 FILE * stream)
29 /* FUNCTION
30 Flush a stream. If the stream is an input stream, then the stream
31 is synchronised for unbuffered I/O. If the stream is an output
32 stream, then any buffered data is written.
34 INPUTS
35 stream - Flush this stream. May be NULL. In this case, all
36 output streams are flushed.
38 RESULT
39 0 on success or EOF on error.
41 NOTES
43 EXAMPLE
45 BUGS
47 SEE ALSO
49 INTERNALS
51 ******************************************************************************/
53 struct aroscbase *aroscbase = __aros_getbase_aroscbase();
55 /* flush all streams opened for output */
56 if (!stream)
58 FILENODE *fn;
60 ForeachNode (&aroscbase->acb_stdio_files, fn)
62 if (fn->File.flags & _STDIO_WRITE)
64 fdesc *fdesc = __getfdesc(fn->File.fd);
66 if (!fdesc)
68 errno = EBADF;
69 return EOF;
72 if (!Flush((BPTR)fdesc->fcb->fh))
74 errno = __arosc_ioerr2errno(IoErr());
75 return EOF;
80 else
82 fdesc *fdesc = __getfdesc(stream->fd);
84 if (!fdesc || !(stream->flags & _STDIO_WRITE))
86 errno = EBADF;
87 return EOF;
90 if (Flush((BPTR)fdesc->fcb->fh))
91 return 0;
94 errno = __arosc_ioerr2errno(IoErr());
95 return EOF;
96 } /* fflush */