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

  1. /* fflush.c (emx+gcc) -- Copyright (c) 1990-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <stdio.h>
  5. #include <fcntl.h>
  6. #include <sys/ioctl.h>
  7. #include <io.h>
  8.  
  9. int fflush (FILE *stream)
  10. {
  11.   int result, n, ft;
  12.   long pos;
  13.  
  14.   result = 0;
  15.   if ((stream->flags & _IOWRT) && bbuf (stream))
  16.     {
  17.       n = stream->ptr - stream->buffer;
  18.       if (n > 0 && write (fileno (stream), stream->buffer, n) <= 0)
  19.         {
  20.           stream->flags |= _IOERR;
  21.           result = EOF;
  22.         }
  23.     }
  24.   if ((stream->flags & _IOREAD) && bbuf (stream) &&
  25.       ioctl (fileno (stream), FGETHTYPE, &ft) >= 0 && ft == HT_FILE)
  26.     {
  27.       pos = ftell (stream);
  28.       if (pos == -1L)
  29.         result = EOF;
  30.       else if (lseek (fileno (stream), pos, SEEK_SET) == -1L)
  31.         result = EOF;
  32.     }
  33.   stream->ptr = stream->buffer;
  34.   stream->rcount = 0;
  35.   stream->wcount = 0;
  36.   stream->flags &= ~_IOREREAD;    /* Undo ungetc */
  37.   return (result);
  38. }
  39.