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

  1. /*[]------------------------------------------------------------[]*/
  2. /*|                                                              |*/
  3. /*|     fsbattch.cpp                                             |*/
  4. /*|                                                              |*/
  5. /*|     Class filebuf                                            |*/
  6. /*|          filebuf* filebuf::attach( 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. // attach this filebuf to open file descriptor -- assume fd is actually open
  23.  
  24. filebuf* filebuf::attach(int f)
  25. {
  26.     if( opened )
  27.         return 0;
  28.  
  29.     xfd = f;        // assumed to be valid
  30.     opened = 1;     // unless we can find out otherwise
  31.     mode = 0;       // unless we can find out otherwise
  32.     char *b = base();       // buffer address
  33.     if( ! b )
  34.         {
  35.         b = new char[B_size];
  36.         if( b )
  37.             setb(b, b+B_size, 1);   // ~streambuf() will delete buffer
  38.         }
  39.     int pb = b ? ((blen() > 8) ? 4 : 1) : 0;    // putback area size
  40.     setp(b+pb, b+pb);
  41.     setg(b, b+pb, b+pb);
  42.     return this;
  43. }
  44.  
  45.  
  46.