Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1997
  6. //
  7. // File: zstr.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. //
  11. // ZSTR.CPP
  12. //
  13. #include <iostream>
  14. #include <fstream>
  15. #include <stdarg.h>
  16. #include <stdio.h>
  17. #include "zstr.h"
  18. void ZSTR :: Vsprintf ( SZC szcFmt, va_list valist )
  19. {
  20. // Attempt to "sprintf" the buffer. If it fails, reallocate
  21. // a larger buffer and try again.
  22. UINT cbMaxNew = 0;
  23. char * psz = NULL;
  24. INT cbOut;
  25. do {
  26. delete psz;
  27. if ( cbMaxNew == 0 )
  28. cbMaxNew = 256;
  29. else
  30. cbMaxNew += cbMaxNew / 2;
  31. psz = new char[cbMaxNew];
  32. } while ( (cbOut = ::_vsnprintf( psz, cbMaxNew-1, szcFmt, valist )) < 0 ) ;
  33. psz[cbOut] = 0;
  34. self = psz;
  35. delete psz;
  36. }
  37. void ZSTR :: Format ( SZC szcFmt, ... )
  38. {
  39. va_list valist;
  40. va_start( valist, szcFmt );
  41. Vsprintf( szcFmt, valist ) ;
  42. va_end( valist );
  43. }
  44. void ZSTR :: FormatAppend ( SZC szcFmt, ... )
  45. {
  46. ZSTR strTemp ;
  47. va_list valist;
  48. va_start( valist, szcFmt );
  49. strTemp.Vsprintf( szcFmt, valist ) ;
  50. va_end( valist );
  51. self += strTemp;
  52. }