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.

207 lines
4.8 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. tstring.h
  5. Abstract:
  6. This include file contains manifests and macros to be used to integrate
  7. the TCHAR and LPTSTR definitions
  8. Note that our naming convention is that a "size" indicates a number of
  9. bytes whereas a "length" indicates a number of characters.
  10. Author:
  11. Richard Firth (rfirth) 02-Apr-1991
  12. Environment:
  13. Portable (Win/32).
  14. Requires ANSI C extensions: slash-slash comments, long external names,
  15. _ultoa() routine.
  16. Revision History:
  17. 22-May-1991 Danl
  18. Added STRSIZE macro
  19. 19-May-1991 JohnRo
  20. Changed some parm names to make things easier to read.
  21. 15-May-1991 rfirth
  22. Added TCHAR_SPACE and MAKE_TCHAR() macro
  23. 15-Jul-1991 RFirth
  24. Added STRING_SPACE_REQD() and DOWN_LEVEL_STRSIZE
  25. 05-Aug-1991 JohnRo
  26. Added MEMCPY macro.
  27. 19-Aug-1991 JohnRo
  28. Added character type stuff: ISDIGIT(), TOUPPER(), etc.
  29. 20-Aug-1991 JohnRo
  30. Changed strnicmp to _strnicmp to keep PC-LINT happy. Ditto stricmp.
  31. 13-Sep-1991 JohnRo
  32. Need UNICODE STRSIZE() too.
  33. 13-Sep-1991 JohnRo
  34. Added UNICODE STRCMP() and various others.
  35. 18-Oct-1991 JohnRo
  36. Added NetpCopy routines and WCSSIZE().
  37. 26-Nov-1991 JohnRo
  38. Added NetpNCopy routines (like strncpy but do conversions as well).
  39. 09-Dec-1991 rfirth
  40. Added STRREV
  41. 03-Jan-1992 JohnRo
  42. Added NetpAlloc{type}From{type} routines and macros.
  43. 09-Jan-1992 JohnRo
  44. Added ATOL() macro and wtol() routine.
  45. Ditto ULTOA() macro and ultow() routine.
  46. 13-Jan-1992 JohnRo
  47. Oops, I missed from NetpAlloc{type}From{type} macros
  48. Also added STRNCMPI as an alias for STRNICMP.
  49. 16-Jan-1992 Danl
  50. Moved the macros to \private\inc\tstr.h
  51. 23-Mar-1992 JohnRo
  52. Added NetpCopy{Str,TStr,WStr}ToUnalignedWStr().
  53. 27-Apr-1992 JohnRo
  54. Changed NetpNCopy{type}From{type} to return NET_API_STATUS.
  55. 03-Aug-1992 JohnRo
  56. RAID 1895: Net APIs and svcs should use OEM char set.
  57. 14-Apr-1993 JohnRo
  58. RAID 6113 ("PortUAS: dangerous handling of Unicode").
  59. Made changes suggested by PC-LINT 5.0
  60. --*/
  61. #ifndef _TSTRING_H_INCLUDED
  62. #define _TSTRING_H_INCLUDED
  63. #include <lmcons.h> // NET_API_STATUS.
  64. // Don't complain about "unneeded" includes of these files:
  65. /*lint -efile(764,tstr.h,winerror.h) */
  66. /*lint -efile(766,tstr.h,winerror.h) */
  67. #include <tstr.h> // tstring stuff, used in macros below.
  68. #include <winerror.h> // NO_ERROR.
  69. //
  70. // Eventually, most uses of non-UNICODE strings should refer to the default
  71. // codepage for the LAN. The NetpCopy functions support the default codepage.
  72. // The other STR macros may not.
  73. //
  74. VOID
  75. NetpCopyStrToWStr(
  76. OUT LPWSTR Dest,
  77. IN LPSTR Src // string in default LAN codepage
  78. );
  79. NET_API_STATUS
  80. NetpNCopyStrToWStr(
  81. OUT LPWSTR Dest,
  82. IN LPSTR Src, // string in default LAN codepage
  83. IN DWORD CharCount
  84. );
  85. VOID
  86. NetpCopyWStrToStr(
  87. OUT LPSTR Dest, // string in default LAN codepage
  88. IN LPWSTR Src
  89. );
  90. NET_API_STATUS
  91. NetpNCopyWStrToStr(
  92. OUT LPSTR Dest, // string in default LAN codepage
  93. IN LPWSTR Src,
  94. IN DWORD CharCount
  95. );
  96. VOID
  97. NetpCopyWStrToStrDBCS(
  98. OUT LPSTR Dest, // string in default LAN codepage
  99. IN LPWSTR Src
  100. );
  101. VOID
  102. NetpCopyWStrToStrDBCSN(
  103. OUT LPSTR Dest, // string in default LAN codepage
  104. IN LPWSTR Src,
  105. IN DWORD MaxStringSize
  106. );
  107. ULONG
  108. NetpUnicodeToDBCSLen(
  109. IN LPWSTR Src
  110. );
  111. #ifdef UNICODE
  112. #define NetpCopyStrToTStr(Dest,Src) NetpCopyStrToWStr((Dest),(Src))
  113. #define NetpCopyTStrToStr(Dest,Src) NetpCopyWStrToStr((LPSTR)(Dest),(LPWSTR)(Src))
  114. #define NetpCopyTStrToWStr(Dest,Src) (void) wcscpy((Dest),(Src))
  115. #define NetpNCopyTStrToWStr(Dest,Src,Len) \
  116. (wcsncpy((Dest),(Src),(Len)), NO_ERROR)
  117. #endif // UNICODE
  118. //
  119. // Define a set of allocate and copy functions. These all return NULL if
  120. // unable to allocate memory. The memory must be freed with NetApiBufferFree.
  121. //
  122. LPSTR
  123. NetpAllocStrFromStr (
  124. IN LPSTR Src
  125. );
  126. LPSTR
  127. NetpAllocStrFromWStr (
  128. IN LPWSTR Src
  129. );
  130. LPWSTR
  131. NetpAllocWStrFromStr (
  132. IN LPSTR Src
  133. );
  134. LPWSTR
  135. NetpAllocWStrFromWStr (
  136. IN LPWSTR Src
  137. );
  138. //
  139. // As of 03-Aug-1992, people are still arguing over whether there should
  140. // be an RtlInitOemString. So I'm inventing NetpInitOemString in the
  141. // meantime. --JR
  142. //
  143. #ifdef _NTDEF_ // POEM_STRING typedef visible?
  144. VOID
  145. NetpInitOemString(
  146. OUT POEM_STRING DestinationString,
  147. IN PCSZ SourceString
  148. );
  149. #endif // _NTDEF_
  150. //
  151. //
  152. // ANSI versions of the API.
  153. //
  154. LPWSTR
  155. NetpAllocWStrFromAStr (
  156. IN LPCSTR Src
  157. );
  158. LPSTR
  159. NetpAllocAStrFromWStr (
  160. IN LPCWSTR Src
  161. );
  162. #endif // _TSTRING_H_INCLUDED