home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / IO / FILL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  1.1 KB  |  44 lines

  1. /* fill.c (emx+gcc) -- Copyright (c) 1990-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <stdio.h>
  5. #include <io.h>
  6. #include <fcntl.h>
  7. #include <errno.h>
  8.  
  9. int _fill (FILE *stream)
  10. {
  11.   if (!(stream->flags & _IOOPEN) || (stream->flags & _IOSTRING))
  12.     {
  13.       errno = EACCES;
  14.       return (EOF);
  15.     }
  16.   if (stream->flags & _IOWRT)   /* File in write mode? */
  17.     {
  18.       stream->flags |= _IOERR;
  19.       errno = EACCES;
  20.       return (EOF);
  21.     }
  22.   stream->flags |= _IOREAD;     /* Switch to read mode */
  23.   stream->wcount = 0;
  24.   stream->flags &= ~_IOREREAD;  /* Buffer empty, no reread required */
  25.   if (nbuf (stream))
  26.     _fbuf (stream);
  27.   else
  28.     stream->ptr = stream->buffer;
  29.   stream->rcount = read (fileno (stream), stream->buffer, stream->buf_size);
  30.   if (stream->rcount == 0)
  31.     {
  32.       stream->flags |= _IOEOF;
  33.       return (EOF);
  34.     }
  35.   if (stream->rcount < 0)
  36.     {
  37.       stream->flags |= _IOERR;
  38.       stream->rcount = 0;
  39.       return (EOF);
  40.     }
  41.   --stream->rcount;
  42.   return ((unsigned char)*stream->ptr++);
  43. }
  44.