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

  1. /*[]------------------------------------------------------------[]*/
  2. /*|                                                              |*/
  3. /*|     fsboflow.cpp                                             |*/
  4. /*|                                                              |*/
  5. /*|     Class filebuf                                            |*/
  6. /*|          int filebuf::overflow( int )                        |*/
  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. // always flush
  23.  
  24. int filebuf::overflow(int c)
  25. {
  26.     if( ! opened  ||  (mode & (ios::in | ios::out)) == ios::in )
  27.         return EOF;
  28.  
  29.     if( unbuffered()  ||  ! base() )
  30.         {
  31.         if( c != EOF )
  32.             {
  33.             char b = c;
  34.             if( ::write(xfd, &b, 1) != 1 )
  35.                 return EOF;
  36.             }
  37.         }
  38.     else
  39.         {
  40.         // now we know this is buffered and state is not bad
  41.  
  42.         // resets get and put areas
  43.         if (sync() != 0)
  44.                 return EOF;
  45.  
  46.         // reset get and put areas
  47.         int pb = (blen() > 8) ? 4 : 1;  // putback area size
  48.         char *b = base();
  49.         setp(b+pb, b+blen());
  50.         setg(b, b+pb, b+pb);
  51.  
  52.         if( c != EOF )
  53.             {
  54.             sputc(c);
  55.             gbump(1);       // pptr and gptr must be the same
  56.             }
  57.         }
  58.     return 1;
  59. }
  60.  
  61.  
  62.