home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 316 / libsrc / fflush.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  673 b   |  38 lines

  1.  
  2. /* fflush */
  3.  
  4. #include <file.h>
  5. #include "std-guts.h"
  6.  
  7. fflush (f)
  8. struct file * f;
  9. {
  10.   if (f && f->open_p &&
  11.     (((f->mode & 0x03) == O_WRONLY) || ((f->mode & 0x03) == O_RDWR)))    
  12.     {
  13.     int err;
  14.     int len = f->buf_max;
  15.  
  16.     if (len > 0)
  17.         {
  18. #ifdef DEBUG
  19.         char buf[64];
  20.  
  21.         sprintf(buf, "\r\n\r\nfflush: write(%d, %X, %d)\r\n\r\n",
  22.                 f->handle, &f->buf, len);
  23.         dbgstr(buf);
  24. #endif
  25.         err = write(f->handle, &f->buf, len);
  26.         if (err < 0)
  27.             f->last_file_error = err;
  28.             else
  29.             f->last_file_error = 0;
  30. #ifdef DEBUG
  31.         dbgstr("\r\n\r\nfflush: write complete\r\n\r\n");
  32. #endif
  33.         }
  34.     f->file_position += len;
  35.     f->buf_index = f->buf_max = 0;
  36.     }
  37. }
  38.