Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <libc/stubs.h>
  3. #include <stdio.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <libc/file.h>
  9.  
  10. int fflush(FILE *f)
  11. {
  12.   char *base;
  13.   int n, rn;
  14.   if(!f) return 0;
  15.   if(f->std_ops && STM_OP(f,flush))
  16.    return STM_OP(f,flush)(f);
  17.   if ((f->_flag&(_IONBF|_IOWRT))==_IOWRT
  18.       && (base = f->_base) != NULL
  19.       && (rn = n = f->_ptr - base) > 0)
  20.   {
  21.     f->_ptr = base;
  22.     f->_cnt = (f->_flag&(_IOLBF|_IONBF)) ? 0 : f->_bufsiz;
  23.     do {
  24.       n = write(fileno(f), base, rn);
  25.       if (n <= 0) {
  26.         f->_flag |= _IOERR;
  27.         return EOF;
  28.       }
  29.       rn -= n;
  30.       base += n;
  31.     } while (rn > 0);
  32.     _dosemu_flush(fileno(f));
  33.   }
  34.   if (f->_flag & _IORW)
  35.   {
  36.     f->_cnt = 0;
  37.     f->_flag &= ~(_IOWRT|_IOREAD);
  38.     f->_ptr = f->_base;
  39.   }
  40.   return 0;
  41. }
  42.