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.

181 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. strmem.h
  5. Abstract:
  6. The header file for allocation-based string routines
  7. Author:
  8. Jim Schmidt (jimschm) 25-Jun-2001
  9. Revision History:
  10. <alias> <date> <comments>
  11. --*/
  12. #pragma once
  13. #include "growbuf.h"
  14. //
  15. // Function Prototypes
  16. //
  17. #define SzAllocBytesA(bytes_incl_nul) ((PSTR) MemFastAlloc(bytes_incl_nul))
  18. #define SzAllocA(logchars_incl_nul) SzAllocBytesA((logchars_incl_nul) * 3)
  19. #define SzAllocBytesW(bytes_incl_nul) ((PWSTR) MemFastAlloc(bytes_incl_nul))
  20. #define SzAllocW(logchars_incl_nul) SzAllocBytesW((logchars_incl_nul) * 2)
  21. __inline
  22. PSTR
  23. RealSzDuplicateA (
  24. IN PCSTR String
  25. )
  26. {
  27. UINT bytes;
  28. PSTR result;
  29. bytes = SzSizeA (String);
  30. result = (PSTR) MemFastAllocNeverFail (bytes);
  31. CopyMemory (result, String, bytes);
  32. return result;
  33. }
  34. __inline
  35. PWSTR
  36. RealSzDuplicateW (
  37. IN PCWSTR String
  38. )
  39. {
  40. UINT bytes;
  41. PWSTR result;
  42. bytes = SzSizeW (String);
  43. result = (PWSTR) MemFastAllocNeverFail (bytes);
  44. CopyMemory (result, String, bytes);
  45. return result;
  46. }
  47. __inline
  48. PSTR
  49. RealSzDuplicateExA (
  50. IN PCSTR String,
  51. OUT PUINT SizeOfString
  52. )
  53. {
  54. PSTR result;
  55. *SizeOfString = SzSizeA (String);
  56. result = (PSTR) MemFastAllocNeverFail (*SizeOfString);
  57. CopyMemory (result, String, *SizeOfString);
  58. return result;
  59. }
  60. __inline
  61. PWSTR
  62. RealSzDuplicateExW (
  63. IN PCWSTR String,
  64. OUT PUINT SizeOfString
  65. )
  66. {
  67. PWSTR result;
  68. *SizeOfString = SzSizeW (String);
  69. result = (PWSTR) MemFastAllocNeverFail (*SizeOfString);
  70. CopyMemory (result, String, *SizeOfString);
  71. return result;
  72. }
  73. #ifdef DEBUG
  74. //
  75. // Wrap duplicates for leak detection in checked build
  76. //
  77. #define SzDuplicateA(str) DBGTRACK(PSTR,SzDuplicateA,(str))
  78. #define SzDuplicateW(str) DBGTRACK(PWSTR,SzDuplicateW,(str))
  79. #define SzDuplicateExA(str,outsize) DBGTRACK(PSTR,SzDuplicateExA,(str,outsize))
  80. #define SzDuplicateExW(str,outsize) DBGTRACK(PWSTR,SzDuplicateExW,(str,outsize))
  81. #else
  82. //
  83. // No wrapping
  84. //
  85. #define SzDuplicateA RealSzDuplicateA
  86. #define SzDuplicateW RealSzDuplicateW
  87. #define SzDuplicateExA RealSzDuplicateExA
  88. #define SzDuplicateExW RealSzDuplicateExW
  89. #endif
  90. #define SzFreeA(string) MemFastFree(string)
  91. #define SzFreeW(string) MemFastFree(string)
  92. PSTR
  93. RealSzJoinPathsA (
  94. IN PCSTR BasePath,
  95. IN PCSTR ChildPath OPTIONAL
  96. );
  97. PWSTR
  98. RealSzJoinPathsW (
  99. IN PCWSTR BasePath,
  100. IN PCWSTR ChildPath OPTIONAL
  101. );
  102. #define SzJoinPathsA(p1,p2) DBGTRACK(PSTR,SzJoinPathsA,(p1,p2))
  103. #define SzJoinPathsW(p1,p2) DBGTRACK(PWSTR,SzJoinPathsW,(p1,p2))
  104. PCSTR
  105. SzJoinPathsExA (
  106. IN OUT PGROWBUFFER Buffer,
  107. IN ...
  108. );
  109. PCWSTR
  110. SzJoinPathsExW (
  111. IN OUT PGROWBUFFER Buffer,
  112. IN ...
  113. );
  114. //
  115. // A & W Macros
  116. //
  117. #ifdef UNICODE
  118. #define SzAlloc SzAllocW
  119. #define SzAllocBytes SzAllocBytesA
  120. #define SzDuplicate SzDuplicateW
  121. #define SzFree SzFreeW
  122. #define SzJoinPaths SzJoinPathsW
  123. #define SzJoinPathsEx SzJoinPathsExW
  124. #else
  125. #define SzAlloc SzAllocA
  126. #define SzAllocBytes SzAllocBytesA
  127. #define SzDuplicate SzDuplicateA
  128. #define SzFree SzFreeA
  129. #define SzJoinPaths SzJoinPathsA
  130. #define SzJoinPathsEx SzJoinPathsExA
  131. #endif