home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / DLIBSSRC.ZIP / FFLUSH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-10-03  |  707 b   |  27 lines

  1. #include <stdio.h>
  2.  
  3. int fflush(fp)
  4. register FILE *fp;
  5. /*
  6.  *    Flush the output buffer of the stream <fp>.  The buffer is
  7.  *    automatically flushed when it is full, the stream is closed,
  8.  *    or the program terminates through exit().  This function has
  9.  *    no effect if the stream in unbuffered.
  10.  */
  11. {
  12.     register int f, rv = 0;
  13.  
  14.     f = fp->F_stat;
  15.     if(!(f & F_BUFFER))            /* file not buffered */
  16.         return(0);
  17.     if(!(f & (F_READ | F_WRITE)))        /* file not open! */
  18.         return(0);
  19.     if((f & F_IODIR) && (fp->F_cnt)) {    /* have data to be written? */
  20.         if(write(fp->F_h, fp->F_buf, fp->F_cnt) < 0)
  21.             fp->F_stat |= F_ERROR;
  22.     }
  23.     fp->F_bp = fp->F_buf;
  24.     fp->F_cnt = 0;
  25.     fp->F_unc1 = fp->F_unc2 = '\0';
  26. }
  27.