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

  1. /*[]------------------------------------------------------------[]*/
  2. /*|                                                              |*/
  3. /*|     srbinit.cpp                                              |*/
  4. /*|                                                              |*/
  5. /*|    Class strstreambuf                                        |*/
  6. /*|    void strstreambuf::init( signed char*, int, signed char* )|*/
  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 <strstrea.h>
  20. #include <limits.h>
  21. #include <string.h>
  22.  
  23. /*
  24.     If n is negative, the provided buffer is supposed to be unlimited.
  25.     As a practical way to handle this, the buffer is arbitrarily defined
  26.     to be size INT_MAX.  (It really should be the max value supported by
  27.     type size_t, but AT&T defined all sizes to be int.)
  28. */
  29.  
  30. void strstreambuf::init( signed char* ptr, int n, signed char* pstart )
  31. {
  32.     ssbflags = 0;
  33.     if( n == 0 )
  34.         n = strlen((char*)ptr);
  35.     else if( n < 0 )
  36.         {
  37.         n = INT_MAX;
  38.         ssbflags |= unlimited;  // distinguish it from merely large
  39.         }
  40.  
  41.     setb((char*)ptr, (char*)ptr+n, 0);
  42.     if( pstart )
  43.         {
  44.         setp((char*)pstart, ebuf());
  45.         setg((char*)ptr, (char*)ptr, (pstart > ptr+n) ?
  46.                                      (char *)ptr+n: (char*)pstart);
  47.         }
  48.     else
  49.         setg((char*)ptr, (char*)ptr, (char*)ebuf());
  50.  
  51.     allocf = 0;
  52.     freef = 0;
  53. }
  54.  
  55.  
  56.