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

  1. /*[]------------------------------------------------------------[]*/
  2. /*|                                                              |*/
  3. /*|     fsbclose.cpp                                             |*/
  4. /*|                                                              |*/
  5. /*|     Class filebuf                                            |*/
  6. /*|          filebuf* filebuf::close()                           |*/
  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. // flush and close file
  23.  
  24. filebuf* filebuf::close()
  25. {
  26.     if( xfd == EOF )
  27.         opened = 0;     // consistency check
  28.  
  29.     if( ! opened )
  30.         return 0;       // nothing to do
  31.  
  32.     int ores = 0;       // result of overflow()
  33.     if( out_waiting() )
  34.         ores = (overflow(EOF) == EOF) ? 1 : 0;
  35.     int cres = ::close(xfd);    // result of system ::close()
  36.  
  37.     xfd = EOF;
  38.     opened = 0;
  39.     return (ores | cres) ? 0 : this;
  40. }
  41.  
  42.  
  43.