home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GEMini Atari
/
GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso
/
zip
/
mint
/
mntlib16.lzh
/
MNTLIB16
/
FILBUF.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-03
|
1KB
|
48 lines
/*
* fill and process an input buffer
* called only when fp->_cnt < 0
*
* more hacks, the initial impl bit!
*
* ++jrb bammi@dsrgsun.ces.cwru.edu
*
* do not remember EOF if input comes from a tty (er)
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <memory.h>
#include "lib.h"
#ifdef __GNUC__
#define alloca __builtin_alloca
#endif
int _filbuf(fp)
FILE *fp;
{
register unsigned int f;
register long got;
f = fp->_flag;
if(f & _IORW) f = (fp->_flag |= _IOREAD);
if(!(f & _IOREAD) || (f & (_IOERR | _IOEOF)))
return(EOF);
/* if this is stdin & a tty, and stdout is line buffered, flush it */
if((fp == stdin) && (f & _IODEV) && (stdout->_flag & _IOLBF))
(void)fflush(stdout);
fp->_ptr = fp->_base;
if((got = _read(fp->_file, fp->_base, (long)fp->_bsiz)) <= 0)
{ /* EOF or error */
fp->_flag |= ((got == 0) ? ((f & _IODEV) ? 0 : _IOEOF) : _IOERR);
return EOF;
}
fp->_cnt = got - 1;
return *(fp->_ptr)++;
}