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.

320 lines
9.4 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ntrtlpath.h
  5. Abstract:
  6. Broken out from nturtl and rtl so I can move it between them in seperate
  7. trees without merge madness. To be integrated into ntrtl.h
  8. Author:
  9. Jay Krell (a-JayK) December 2000
  10. Environment:
  11. Revision History:
  12. --*/
  13. #ifndef _NTRTL_PATH_
  14. #define _NTRTL_PATH_
  15. #if _MSC_VER >= 1100
  16. #pragma once
  17. #endif
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #if defined (_MSC_VER)
  22. #if ( _MSC_VER >= 800 )
  23. #pragma warning(disable:4514)
  24. #if _MSC_VER >= 1200
  25. #pragma warning(push)
  26. #endif
  27. #pragma warning(disable:4001)
  28. #pragma warning(disable:4201)
  29. #pragma warning(disable:4214)
  30. #endif
  31. #endif
  32. //
  33. // not NTSYSAPI so easily statically linked to
  34. //
  35. //
  36. // These are OUT Disposition values.
  37. //
  38. #define RTL_NT_PATH_NAME_TO_DOS_PATH_NAME_AMBIGUOUS (0x00000001)
  39. #define RTL_NT_PATH_NAME_TO_DOS_PATH_NAME_UNC (0x00000002)
  40. #define RTL_NT_PATH_NAME_TO_DOS_PATH_NAME_DRIVE (0x00000003)
  41. #define RTL_NT_PATH_NAME_TO_DOS_PATH_NAME_ALREADY_DOS (0x00000004)
  42. NTSTATUS
  43. NTAPI
  44. RtlNtPathNameToDosPathName(
  45. IN ULONG Flags,
  46. IN OUT PRTL_UNICODE_STRING_BUFFER Path,
  47. OUT ULONG* Disposition OPTIONAL,
  48. IN OUT PWSTR* FilePart OPTIONAL
  49. );
  50. //
  51. // If either Path or Element end in a path seperator, then so does the result.
  52. // The path seperator to put on the end is chosen from the existing ones.
  53. //
  54. #define RTL_APPEND_PATH_ELEMENT_ONLY_BACKSLASH_IS_SEPERATOR (0x00000001)
  55. #define RTL_APPEND_PATH_ELEMENT_BUGFIX_CHECK_FIRST_THREE_CHARS_FOR_SLASH_TAKE_FOUND_SLASH_INSTEAD_OF_FIRST_CHAR (0x00000002)
  56. NTSTATUS
  57. NTAPI
  58. RtlAppendPathElement(
  59. IN ULONG Flags,
  60. IN OUT PRTL_UNICODE_STRING_BUFFER Path,
  61. PCUNICODE_STRING Element
  62. );
  63. //
  64. // c:\foo => c:\
  65. // \foo => empty
  66. // \ => empty
  67. // Trailing slashness is generally preserved.
  68. //
  69. NTSTATUS
  70. NTAPI
  71. RtlGetLengthWithoutLastFullDosPathElement(
  72. IN ULONG Flags,
  73. IN PCUNICODE_STRING Path,
  74. OUT ULONG* LengthOut
  75. );
  76. NTSTATUS
  77. NTAPI
  78. RtlGetLengthWithoutLastNtPathElement(
  79. IN ULONG Flags,
  80. IN PCUNICODE_STRING Path,
  81. OUT ULONG* LengthOut
  82. );
  83. NTSTATUS
  84. NTAPI
  85. RtlGetLengthWithoutLastFullDosOrNtPathElement(
  86. IN ULONG Flags,
  87. IN PCUNICODE_STRING Path,
  88. OUT ULONG* LengthOut
  89. );
  90. NTSTATUS
  91. NTAPI
  92. RtlGetLengthWithoutTrailingPathSeperators(
  93. IN ULONG Flags,
  94. IN PCUNICODE_STRING Path,
  95. OUT ULONG* LengthOut
  96. );
  97. //++
  98. //
  99. // NTSTATUS
  100. // RtlRemoveLastNtPathElement(
  101. // IN ULONG Flags
  102. // IN OUT PUNICODE_STRING UnicodeString
  103. //
  104. // NTSTATUS
  105. // RtlRemoveLastNtPathElement(
  106. // IN ULONG Flags
  107. // IN OUT PRTL_UNICODE_STRING_BUFFER UnicodeStringBuffer
  108. // );
  109. //
  110. // NTSTATUS
  111. // RtlRemoveLastFullDosPathElement(
  112. // IN ULONG Flags
  113. // IN OUT PUNICODE_STRING UnicodeString
  114. //
  115. // NTSTATUS
  116. // RtlRemoveLastFullDosPathElement(
  117. // IN ULONG Flags
  118. // IN OUT PRTL_UNICODE_STRING_BUFFER UnicodeStringBuffer
  119. // );
  120. //
  121. // NTSTATUS
  122. // RtlRemoveLastFullDosOrNtPathElement(
  123. // IN ULONG Flags
  124. // IN OUT PUNICODE_STRING UnicodeString
  125. //
  126. // NTSTATUS
  127. // RtlRemoveLastFullDosOrNtPathElement(
  128. // IN ULONG Flags
  129. // IN OUT PRTL_UNICODE_STRING_BUFFER UnicodeStringBuffer
  130. // );
  131. //
  132. // NTSTATUS
  133. // RtlRemoveTrailingPathSeperators(
  134. // IN ULONG Flags
  135. // IN OUT PUNICODE_STRING UnicodeString
  136. //
  137. // NTSTATUS
  138. // RtlRemoveTrailingPathSeperators(
  139. // IN ULONG Flags
  140. // IN OUT PRTL_UNICODE_STRING_BUFFER UnicodeStringBuffer
  141. // );
  142. //
  143. // Routine Description:
  144. //
  145. // This family of functions the last element from a path, where path is explicitly
  146. // an Nt Path, a full DOS path, or either.
  147. // NT Path:
  148. // Uses only backslash as delimiter.
  149. // Starts with single backslash.
  150. // Full DOS/Win32 Path:
  151. // Uses backslash and forward slash as delimiter.
  152. // Starts with two delimiters or drive-letter-colon-delimiter.
  153. // Also beware the special \\? form.
  154. //
  155. // And paths are stored in UNICODE_STRING or RTL_UNICODE_STRING_BUFFER.
  156. // UNICODE_STRING is shortened just by changing the length, RTL_UNICODE_STRING_BUFFER
  157. // also get a terminal nul written into them.
  158. //
  159. // There were more comments here, but the file got copied over by accident.
  160. //
  161. // Arguments:
  162. //
  163. // Flags -
  164. // UnicodeString -
  165. // UnicodeStringBuffer -
  166. //
  167. // Return Value:
  168. //
  169. // STATUS_INVALID_PARAMETER
  170. // STATUS_SUCCESS
  171. //--
  172. NTSTATUS
  173. NTAPI
  174. RtlpApplyLengthFunction(
  175. IN ULONG Flags,
  176. IN SIZE_T SizeOfStruct,
  177. IN OUT PVOID UnicodeStringOrUnicodeStringBuffer,
  178. NTSTATUS (NTAPI* LengthFunction)(ULONG, PCUNICODE_STRING, ULONG*)
  179. );
  180. #define RtlRemoveLastNtPathElement(Flags, Path) \
  181. (RtlpApplyLengthFunction((Flags), sizeof(*Path), (Path), RtlGetLengthWithoutLastNtPathElement))
  182. #define RtlRemoveLastFullDosPathElement(Flags, Path) \
  183. (RtlpApplyLengthFunction((Flags), sizeof(*Path), (Path), RtlGetLengthWithoutLastFullDosPathElement))
  184. #define RtlRemoveLastFullDosOrNtPathElement(Flags, Path) \
  185. (RtlpApplyLengthFunction((Flags), sizeof(*Path), (Path), RtlGetLengthWithoutLastFullDosOrNtPathElement))
  186. #define RtlRemoveTrailingPathSeperators(Flags, Path) \
  187. (RtlpApplyLengthFunction((Flags), sizeof(*Path), (Path), RtlGetLengthWithoutTrailingPathSeperators))
  188. //
  189. // Such small pieces of data are not worth exporting.
  190. // If you want any of this data in char form, just take the first char from the string.
  191. //
  192. #if !(defined(SORTPP_PASS) || defined(MIDL_PASS)) // Neither the Wow64 thunk generation tools nor midl accept this.
  193. #if defined(RTL_CONSTANT_STRING) // Some code gets here without this defined.
  194. #if defined(_MSC_VER) && (_MSC_VER >= 1100) // VC5 for __declspec(selectany)
  195. __declspec(selectany) extern const UNICODE_STRING RtlNtPathSeperatorString = RTL_CONSTANT_STRING(L"\\");
  196. __declspec(selectany) extern const UNICODE_STRING RtlDosPathSeperatorsString = RTL_CONSTANT_STRING(L"\\/");
  197. __declspec(selectany) extern const UNICODE_STRING RtlAlternateDosPathSeperatorString = RTL_CONSTANT_STRING(L"/");
  198. #else
  199. static const UNICODE_STRING RtlNtPathSeperatorString = RTL_CONSTANT_STRING(L"\\");
  200. static const UNICODE_STRING RtlDosPathSeperatorsString = RTL_CONSTANT_STRING(L"\\/");
  201. static const UNICODE_STRING RtlAlternateDosPathSeperatorString = RTL_CONSTANT_STRING(L"/");
  202. #endif // defined(_MSC_VER) && (_MSC_VER >= 1100)
  203. #else
  204. #if defined(_MSC_VER) && (_MSC_VER >= 1100) // VC5 for __declspec(selectany)
  205. __declspec(selectany) extern const UNICODE_STRING RtlNtPathSeperatorString = { 1 * sizeof(WCHAR), 2 * sizeof(WCHAR), L"\\" };
  206. __declspec(selectany) extern const UNICODE_STRING RtlDosPathSeperatorsString = { 2 * sizeof(WCHAR), 3 * sizeof(WCHAR), L"\\/" };
  207. __declspec(selectany) extern const UNICODE_STRING RtlAlternateDosPathSeperatorString = { 1 * sizeof(WCHAR), 2 * sizeof(WCHAR), L"/" };
  208. #else
  209. static const UNICODE_STRING RtlNtPathSeperatorString = { 1 * sizeof(WCHAR), 2 * sizeof(WCHAR), L"\\" };
  210. static const UNICODE_STRING RtlDosPathSeperatorsString = { 2 * sizeof(WCHAR), 3 * sizeof(WCHAR), L"\\/" };
  211. static const UNICODE_STRING RtlAlternateDosPathSeperatorString = { 1 * sizeof(WCHAR), 2 * sizeof(WCHAR), L"/" };
  212. #endif // defined(_MSC_VER) && (_MSC_VER >= 1100)
  213. #endif // defined(RTL_CONSTANT_STRING)
  214. #define RtlCanonicalDosPathSeperatorString RtlNtPathSeperatorString
  215. #define RtlPathSeperatorString RtlNtPathSeperatorString
  216. #endif
  217. //++
  218. //
  219. // WCHAR
  220. // RTL_IS_DOS_PATH_SEPARATOR(
  221. // IN WCHAR Ch
  222. // );
  223. //
  224. // Routine Description:
  225. //
  226. // Arguments:
  227. //
  228. // Ch -
  229. //
  230. // Return Value:
  231. //
  232. // TRUE if ch is \\ or /.
  233. // FALSE otherwise.
  234. //--
  235. #define RTL_IS_DOS_PATH_SEPARATOR(ch_) ((ch_) == '\\' || ((ch_) == '/'))
  236. #define RTL_IS_DOS_PATH_SEPERATOR(ch_) RTL_IS_DOS_PATH_SEPARATOR(ch_)
  237. #if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER >= 1100 // VC5 for bool
  238. inline bool RtlIsDosPathSeparator(WCHAR ch) { return RTL_IS_DOS_PATH_SEPARATOR(ch); }
  239. inline bool RtlIsDosPathSeperator(WCHAR ch) { return RTL_IS_DOS_PATH_SEPARATOR(ch); }
  240. #endif
  241. //
  242. // compatibility
  243. //
  244. #define RTL_IS_PATH_SEPERATOR RTL_IS_DOS_PATH_SEPERATOR
  245. #define RTL_IS_PATH_SEPARATOR RTL_IS_DOS_PATH_SEPERATOR
  246. #define RtlIsPathSeparator RtlIsDosPathSeparator
  247. #define RtlIsPathSeperator RtlIsDosPathSeparator
  248. //++
  249. //
  250. // WCHAR
  251. // RTL_IS_NT_PATH_SEPARATOR(
  252. // IN WCHAR Ch
  253. // );
  254. //
  255. // Routine Description:
  256. //
  257. // Arguments:
  258. //
  259. // Ch -
  260. //
  261. // Return Value:
  262. //
  263. // TRUE if ch is \\.
  264. // FALSE otherwise.
  265. //--
  266. #define RTL_IS_NT_PATH_SEPARATOR(ch_) ((ch_) == '\\')
  267. #define RTL_IS_NT_PATH_SEPERATOR(ch_) RTL_IS_NT_PATH_SEPARATOR(ch_)
  268. #if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER >= 1100 // VC5 for bool
  269. inline bool RtlIsNtPathSeparator(WCHAR ch) { return RTL_IS_NT_PATH_SEPARATOR(ch); }
  270. inline bool RtlIsNtPathSeperator(WCHAR ch) { return RTL_IS_NT_PATH_SEPARATOR(ch); }
  271. #endif
  272. #ifdef __cplusplus
  273. } // extern "C"
  274. #endif
  275. #if defined (_MSC_VER) && ( _MSC_VER >= 800 )
  276. #if _MSC_VER >= 1200
  277. #pragma warning(pop)
  278. #else
  279. #pragma warning(default:4001)
  280. #pragma warning(default:4201)
  281. #pragma warning(default:4214)
  282. #endif
  283. #endif
  284. #endif