home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 9.ddi / IOSTRSR1.ZIP / SDBSYNC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.4 KB  |  50 lines

  1. /*[]------------------------------------------------------------[]*/
  2. /*|                                                              |*/
  3. /*|     sdbsync.cpp                                              |*/
  4. /*|                                                              |*/
  5. /*|     Class stdiobuf                                           |*/
  6. /*|          int stdiobuf::sync()                                |*/
  7. /*|                                                              |*/
  8. /*[]------------------------------------------------------------[]*/
  9.  
  10. /*
  11.  *      C/C++ Run Time Library - Version 5.0
  12.  *
  13.  *      Copyright (c) 1990, 1992 by Borland International
  14.  *      All Rights Reserved.
  15.  *
  16.  */
  17.  
  18. #include <ioconfig.h>
  19. #include <filesys.h>
  20. #include <stdiostr.h>
  21.  
  22. int stdiobuf::sync()
  23. {
  24.     int count;
  25.     if( out_waiting() )
  26.         {
  27.         if( overflow(EOF) == EOF )
  28.             return EOF;
  29.         }
  30.     else if( (count = in_avail()) > 0 )
  31.         {
  32.         char *p = egptr();
  33.         do  {
  34.             --p;
  35.             ungetc(*p, sio);
  36.             --count;
  37.             } while( count );
  38.         p = egptr();
  39.         setp(p, p);
  40.         setg(eback(), p, p);
  41.         }
  42.     /*
  43.      * We assume that fseek() does any needed synchronization.
  44.      */
  45.     fseek(sio, 0L, SEEK_CUR);   // should flush stdio buffer
  46.     return ferror(sio) ? EOF : 0;
  47. }
  48.  
  49.  
  50.