1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1987-01-27 15:57:55 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
_flushbuf(c, iop)
|
|
|
|
register FILE *iop;
|
|
|
|
{
|
|
|
|
if (fileno(iop) < 0) return EOF;
|
|
|
|
if (! io_testflag(iop, IO_UNBUFF)) {
|
|
|
|
if (iop->_buf == 0) {
|
1989-02-21 10:01:55 +00:00
|
|
|
if (iop == stdout && isatty(fileno(stdout))) {
|
|
|
|
iop->_flags |= IO_UNBUFF;
|
1987-01-27 15:57:55 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
extern char *malloc();
|
1989-02-21 10:01:55 +00:00
|
|
|
|
|
|
|
if (!(iop->_buf = (unsigned char *) malloc(_BUFSIZ))) {
|
1987-01-27 15:57:55 +00:00
|
|
|
iop->_flags |= IO_UNBUFF;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
iop->_flags |= IO_MYBUF;
|
1989-02-21 10:01:55 +00:00
|
|
|
iop->_bufsiz = _BUFSIZ;
|
|
|
|
iop->_count = _BUFSIZ-1;
|
1987-01-27 15:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
1987-02-06 10:37:09 +00:00
|
|
|
iop->_ptr = iop->_buf;
|
1987-01-27 15:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (io_testflag(iop, IO_UNBUFF)) {
|
|
|
|
char c1 = c;
|
|
|
|
|
|
|
|
iop->_count = 0;
|
|
|
|
if (write(fileno(iop), &c1, 1) != 1) {
|
|
|
|
iop->_flags |= IO_ERR;
|
|
|
|
return EOF;
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
else {
|
1987-02-06 10:37:09 +00:00
|
|
|
int count = iop->_ptr - iop->_buf;
|
1987-01-27 15:57:55 +00:00
|
|
|
|
1989-02-21 10:01:55 +00:00
|
|
|
iop->_count = iop->_bufsiz - 1;
|
1987-01-27 15:57:55 +00:00
|
|
|
iop->_ptr = iop->_buf + 1;
|
|
|
|
|
|
|
|
if (count > 0) {
|
|
|
|
if (write(fileno(iop), iop->_buf, count) != count) {
|
|
|
|
*(iop->_buf) = c;
|
|
|
|
iop->_flags |= IO_ERR;
|
|
|
|
return EOF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*(iop->_buf) = c;
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
_cleanup()
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
|
|
|
|
for ( i = 0 ; i < _NFILES ; i++ )
|
|
|
|
if ( _io_table[i] != NULL )
|
|
|
|
fclose(_io_table[i]);
|
|
|
|
}
|