Fixed compatibility of output.
[AROS.git] / compiler / posixc / fflush.c
blob8f11b4efc1d1bbb9b441c4cd4cef93435ce43e5b
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function fflush().
6 */
8 #include "__posixc_intbase.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 PosixCIntBase *PosixCBase =
54 (struct PosixCIntBase *)__aros_getbase_PosixCBase();
56 /* flush all streams opened for output */
57 if (!stream)
59 FILENODE *fn;
61 ForeachNode (&PosixCBase->stdio_files, fn)
63 if (fn->File.flags & __POSIXC_STDIO_WRITE)
65 fdesc *fdesc = __getfdesc(fn->File.fd);
67 if (!fdesc)
69 errno = EBADF;
70 return EOF;
73 if (!Flush(fdesc->fcb->handle))
75 errno = __stdc_ioerr2errno(IoErr());
76 return EOF;
81 else
83 fdesc *fdesc = __getfdesc(stream->fd);
85 if (!fdesc || !(stream->flags & __POSIXC_STDIO_WRITE))
87 errno = EBADF;
88 return EOF;
91 if (Flush(fdesc->fcb->handle))
92 return 0;
95 errno = __stdc_ioerr2errno(IoErr());
96 return EOF;
97 } /* fflush */