home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / libnix-0.8-src.lha / libnix-0.8 / sources / nix / stdio / __fflush.c next >
Encoding:
C/C++ Source or Header  |  1994-12-12  |  754 b   |  32 lines

  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <unistd.h>
  4.  
  5. int __fflush(FILE *stream) /* fflush exactly one file */
  6. {
  7.   long size,subsize;
  8.   unsigned char *subbuf;
  9.   if(stream->flags&64) /* Error on stream */
  10.   { errno=EPERM;
  11.     return EOF; }
  12.   if(stream->flags&8) /* Works only on output streams */
  13.   { 
  14.     size=stream->p-stream->buffer; /* calculate size */
  15.     subbuf=stream->buffer;
  16.     while(size)
  17.     {
  18.       if((subsize=write(stream->file,subbuf,size))<0)
  19.       {
  20.         stream->flags|=64; /* error flag */
  21.         return EOF;
  22.       }
  23.       size-=subsize;
  24.       subbuf+=subsize;
  25.     }
  26.     stream->flags&=~8; /* unset write state */
  27.     stream->outcount=0;
  28.     stream->linebufsize=0;
  29.   } /* Nothing to be done for input streams */
  30.   return 0;
  31. }
  32.