home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / filbuf.c < prev    next >
C/C++ Source or Header  |  1993-02-28  |  975b  |  45 lines

  1. /*
  2.  * fill and process an input buffer
  3.  *    called only when fp->_cnt < 0
  4.  *
  5.  * more hacks, the initial impl bit!
  6.  *
  7.  *    ++jrb    bammi@dsrgsun.ces.cwru.edu
  8.  *
  9.  * do not remember EOF if input comes from a tty (er)
  10.  *
  11.  */
  12.  
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <unistd.h>
  17. #include <memory.h>
  18. #include "lib.h"
  19.  
  20. int _filbuf(fp)
  21. FILE *fp;
  22. {
  23.     register unsigned int f;
  24.     register long got;
  25.     
  26.     f = fp->_flag;
  27.     if(f & _IORW) f = (fp->_flag |= _IOREAD);
  28.     if(!(f & _IOREAD) || (f & (_IOERR | _IOEOF)))
  29.     return(EOF);
  30.  
  31.     /* if this is stdin &  a tty, and stdout is line buffered, flush it */
  32.     if((fp == stdin) && (f & _IODEV) && (stdout->_flag & _IOLBF))
  33.     (void)fflush(stdout);
  34.  
  35.     fp->_ptr = fp->_base;
  36.     if((got = _read(fp->_file, fp->_base, (unsigned long)fp->_bsiz)) <= 0)
  37.     {   /* EOF or error */
  38.     fp->_flag |= ((got == 0) ? ((f & _IODEV) ? 0 : _IOEOF) : _IOERR);
  39.     fp->_cnt = 0;
  40.     return EOF;
  41.     }
  42.     fp->_cnt = got - 1;
  43.     return *(fp->_ptr)++;
  44. }
  45.