Replaced Popscren with a custom pop-up list for selecting public screen. Now it conta...
[tangerine.git] / compiler / clib / fflush.c
blobea136bb04af5f8ca3b9c7a5cec1601db53068c12
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C 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 "__open.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 /* flush all streams opened for output */
54 if (!stream)
56 FILENODE *fn;
58 ForeachNode (&__stdio_files, fn)
60 if (fn->File.flags & _STDIO_WRITE)
62 fdesc *fdesc = __getfdesc(fn->File.fd);
64 if (!fdesc)
66 errno = EBADF;
67 return EOF;
70 if (!Flush((BPTR)fdesc->fcb->fh))
72 errno = IoErr2errno(IoErr());
73 return EOF;
78 else
80 fdesc *fdesc = __getfdesc(stream->fd);
82 if (!fdesc || !(stream->flags & _STDIO_WRITE))
84 errno = EBADF;
85 return EOF;
88 if (Flush((BPTR)fdesc->fcb->fh))
89 return 0;
92 errno = IoErr2errno(IoErr());
93 return EOF;
94 } /* fflush */