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

  1. /*[]------------------------------------------------------------[]*/
  2. /*|                                                              |*/
  3. /*|     fsbsync.cpp                                              |*/
  4. /*|                                                              |*/
  5. /*|     Class filebuf                                            |*/
  6. /*|          int filebuf::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 <fstream.h>
  21.  
  22. int filebuf::sync()
  23. {
  24.     if (!opened)
  25.         return EOF;
  26.  
  27.     int count = out_waiting();
  28.     if( count )
  29.         {
  30.         if( ::write(xfd, pbase(), count) != count )
  31.             return EOF;
  32.  
  33.         // reset get and put areas
  34.         int pb = (blen() > 8) ? 4 : 1;  // putback area size
  35.         char *b = base();
  36.         setp(b+pb, b+blen());
  37.         setg(b, b+pb, b+pb);
  38.         }
  39.     else if( in_avail() )
  40.         {
  41.         last_seek = ::lseek(xfd, long(-in_avail()), L_cur);
  42.         setg(eback(), gptr(), gptr());
  43.         setp(gptr(), gptr());
  44.         if( last_seek == long(OS_err) )
  45.             return EOF;
  46.         }
  47.     return 0;
  48. }
  49.  
  50.  
  51.