2 * fflush.c - flush stream(s)
4 /* $Id: fflush.c,v 1.7 1994/06/24 11:48:51 ceriel Exp $ */
10 int _write(int d, const char *buf, int nbytes);
11 off_t _lseek(int fildes, off_t offset, int whence);
16 int count, c1, i, retval = 0;
19 for(i= 0; i < FOPEN_MAX; i++)
20 if (__iotab[i] && fflush(__iotab[i]))
26 || (!io_testflag(stream, _IOREADING)
27 && !io_testflag(stream, _IOWRITING)))
29 if (io_testflag(stream, _IOREADING)) {
30 /* (void) fseek(stream, 0L, SEEK_CUR); */
32 if (stream->_buf && !io_testflag(stream,_IONBF))
33 adjust = stream->_count;
35 _lseek(fileno(stream), (off_t) adjust, SEEK_CUR);
36 if (io_testflag(stream, _IOWRITE))
37 stream->_flags &= ~(_IOREADING | _IOWRITING);
38 stream->_ptr = stream->_buf;
40 } else if (io_testflag(stream, _IONBF)) return 0;
42 if (io_testflag(stream, _IOREAD)) /* "a" or "+" mode */
43 stream->_flags &= ~_IOWRITING;
45 count = stream->_ptr - stream->_buf;
46 stream->_ptr = stream->_buf;
51 if (io_testflag(stream, _IOAPPEND)) {
52 if (_lseek(fileno(stream), 0L, SEEK_END) == -1) {
53 stream->_flags |= _IOERR;
57 c1 = _write(stream->_fd, (char *)stream->_buf, count);
64 stream->_flags |= _IOERR;
73 for(i= 0; i < FOPEN_MAX; i++)
74 if (__iotab[i] && io_testflag(__iotab[i], _IOWRITING))
75 (void) fflush(__iotab[i]);