Leaked source code of windows server 2003
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.

47 lines
2.0 KiB

  1. // --------------------------------------------------------------------------------
  2. // Stackstr.h
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // --------------------------------------------------------------------------------
  5. #ifndef __STACKSTR_H
  6. #define __STACKSTR_H
  7. // --------------------------------------------------------------------------------
  8. // Use this macro to define a stack string within a function
  9. // --------------------------------------------------------------------------------
  10. #define STACKSTRING_DEFINE(_name, _size) \
  11. struct { \
  12. CHAR szScratch[_size]; \
  13. LPSTR pszVal; \
  14. } _name = { '0', NULL };
  15. // --------------------------------------------------------------------------------
  16. // Use this macro to insure that _name::pszVal can hold _cchVal. This macro
  17. // depends on the local variable 'hr', and that there is a label named 'exit' at
  18. // the end of your function.
  19. // --------------------------------------------------------------------------------
  20. #define STACKSTRING_SETSIZE(_name, _cchVal) \
  21. if (NULL != _name.pszVal && _name.pszVal != _name.szScratch) { \
  22. LPSTR psz = (LPSTR)g_pMalloc->Realloc(_name.pszVal, _cchVal); \
  23. if (NULL == psz) { \
  24. hr = TrapError(E_OUTOFMEMORY); \
  25. goto exit; \
  26. } \
  27. _name.pszVal = psz; \
  28. } \
  29. else if (_cchVal <= sizeof(_name.szScratch)) { \
  30. _name.pszVal = _name.szScratch; \
  31. } \
  32. else { \
  33. _name.pszVal = (LPSTR)g_pMalloc->Alloc(_cchVal); \
  34. }
  35. // --------------------------------------------------------------------------------
  36. // Use this macro to free a stack string
  37. // --------------------------------------------------------------------------------
  38. #define STACKSTRING_FREE(_name) \
  39. if (NULL != _name.pszVal && _name.pszVal != _name.szScratch) { \
  40. g_pMalloc->Free(_name.pszVal); \
  41. _name.pszVal = NULL; \
  42. }
  43. #endif // __STACKSTR_H