1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1987-01-27 15:57:55 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
1987-04-02 14:12:21 +00:00
|
|
|
char *malloc();
|
|
|
|
|
1987-01-27 15:57:55 +00:00
|
|
|
_fillbuf(iop)
|
|
|
|
register FILE *iop;
|
|
|
|
{
|
1987-02-06 11:09:26 +00:00
|
|
|
static unsigned char ch[_NFILES];
|
1987-01-27 15:57:55 +00:00
|
|
|
|
|
|
|
iop->_count = 0;
|
|
|
|
if (fileno(iop) < 0) return EOF;
|
|
|
|
if ( io_testflag(iop, (IO_EOF | IO_ERR )))
|
|
|
|
return (EOF);
|
|
|
|
|
|
|
|
if ( !io_testflag(iop, IO_READMODE) )
|
|
|
|
return (EOF);
|
|
|
|
|
|
|
|
if (! io_testflag(iop, IO_UNBUFF) && ! iop->_buf) {
|
1989-02-21 10:01:55 +00:00
|
|
|
iop->_buf = (unsigned char *) malloc(_BUFSIZ);
|
|
|
|
if (! iop->_buf) {
|
|
|
|
iop->_flags |= IO_UNBUFF;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
iop->_flags |= IO_MYBUF;
|
|
|
|
iop->_bufsiz = _BUFSIZ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! iop->_buf) {
|
|
|
|
iop->_buf = &ch[fileno(iop)];
|
|
|
|
iop->_bufsiz = 1;
|
1987-01-27 15:57:55 +00:00
|
|
|
}
|
|
|
|
iop->_ptr = iop->_buf;
|
1989-02-21 10:01:55 +00:00
|
|
|
iop->_count = read(iop->_fd, iop->_buf, iop->_bufsiz);
|
1987-01-27 15:57:55 +00:00
|
|
|
|
|
|
|
if (iop->_count <= 0){
|
|
|
|
if (iop->_count == 0) {
|
|
|
|
iop->_flags |= IO_EOF;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
iop->_flags |= IO_ERR;
|
|
|
|
|
|
|
|
return (EOF);
|
|
|
|
}
|
|
|
|
iop->_count--;
|
|
|
|
|
|
|
|
return *iop->_ptr++;
|
|
|
|
}
|