2 * fflush.c - flush stream(s)
11 ssize_t
_write(int d
, const char *buf
, size_t nbytes
);
12 off_t
_lseek(int fildes
, off_t offset
, int whence
);
17 int count
, c1
, i
, retval
= 0;
20 for(i
= 0; i
< FOPEN_MAX
; i
++)
21 if (__iotab
[i
] && fflush(__iotab
[i
]))
27 || (!io_testflag(stream
, _IOREADING
)
28 && !io_testflag(stream
, _IOWRITING
)))
30 if (io_testflag(stream
, _IOREADING
)) {
31 /* (void) fseek(stream, 0L, SEEK_CUR); */
33 if (io_testflag(stream
, _IOFIFO
)) {
34 /* Can't seek in a pipe. */
37 if (stream
->_buf
&& !io_testflag(stream
,_IONBF
))
38 adjust
= -stream
->_count
;
40 if (_lseek(fileno(stream
), (off_t
) adjust
, SEEK_CUR
) == -1 &&
42 stream
->_flags
|= _IOERR
;
46 if (io_testflag(stream
, _IOWRITE
))
47 stream
->_flags
&= ~(_IOREADING
| _IOWRITING
);
48 stream
->_ptr
= stream
->_buf
;
50 } else if (io_testflag(stream
, _IONBF
)) return 0;
52 if (io_testflag(stream
, _IOREAD
)) /* "a" or "+" mode */
53 stream
->_flags
&= ~_IOWRITING
;
55 count
= stream
->_ptr
- stream
->_buf
;
56 stream
->_ptr
= stream
->_buf
;
61 if (io_testflag(stream
, _IOAPPEND
)) {
62 if (_lseek(fileno(stream
), 0L, SEEK_END
) == -1) {
63 stream
->_flags
|= _IOERR
;
67 c1
= _write(stream
->_fd
, (char *)stream
->_buf
, count
);
74 stream
->_flags
|= _IOERR
;
83 for(i
= 0; i
< FOPEN_MAX
; i
++)
84 if (__iotab
[i
] && io_testflag(__iotab
[i
], _IOWRITING
))
85 (void) fflush(__iotab
[i
]);