1989-05-30 13:34:25 +00:00
|
|
|
/*
|
|
|
|
* fflush.c - flush stream(s)
|
|
|
|
*/
|
|
|
|
/* $Header$ */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "loc_incl.h"
|
|
|
|
|
1989-06-26 10:37:05 +00:00
|
|
|
int write(int d, const char *buf, int nbytes);
|
1989-05-30 13:34:25 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
fflush(FILE *stream)
|
|
|
|
{
|
|
|
|
int count, c1, i, retval = 0;
|
|
|
|
|
|
|
|
if (!stream) {
|
|
|
|
for(i= 0; i < FOPEN_MAX; i++)
|
|
|
|
if (_iotable[i] && fflush(_iotable[i]))
|
|
|
|
retval = EOF;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
1989-06-26 10:37:05 +00:00
|
|
|
if (!stream->_buf
|
|
|
|
|| io_testflag(stream, _IONBF)
|
|
|
|
|| !io_testflag(stream, _IOWRITE)
|
|
|
|
|| !io_testflag(stream, _IOWRITING))
|
|
|
|
return 0;
|
1989-05-30 13:34:25 +00:00
|
|
|
|
1989-06-26 10:37:05 +00:00
|
|
|
if (io_testflag(stream, _IOREAD)) /* "a" or "+" mode */
|
|
|
|
stream->_flags &= ~_IOWRITING;
|
|
|
|
|
|
|
|
/*
|
1989-05-30 13:34:25 +00:00
|
|
|
if (io_testflag(stream, _IOLBF))
|
|
|
|
count = -stream->_count;
|
|
|
|
else count = stream->_bufsiz - stream->_count;
|
1989-06-26 10:37:05 +00:00
|
|
|
*/
|
|
|
|
count = stream->_ptr - stream->_buf;
|
|
|
|
stream->_ptr = stream->_buf;
|
1989-05-30 13:34:25 +00:00
|
|
|
|
|
|
|
if ( count <= 0 )
|
1989-06-26 10:37:05 +00:00
|
|
|
return 0;
|
1989-05-30 13:34:25 +00:00
|
|
|
|
|
|
|
c1 = write(stream->_fd, (char *)stream->_buf, count);
|
|
|
|
|
1989-06-26 10:37:05 +00:00
|
|
|
stream->_count = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
if(stream != stderr)
|
|
|
|
fprintf(stderr,"written %d bytes :\"%.*s\"\n"
|
|
|
|
, c1, c1, stream->_buf);
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( count == c1 )
|
|
|
|
return 0;
|
1989-05-30 13:34:25 +00:00
|
|
|
|
|
|
|
stream->_flags |= _IOERR;
|
1989-06-26 10:37:05 +00:00
|
|
|
return EOF;
|
1989-05-30 13:34:25 +00:00
|
|
|
}
|