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.

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