xref: /reactos/sdk/lib/pathcch/pathcch.h (revision d0e1d360)
1 /*
2  * PROJECT:     ReactOS PSDK
3  * LICENSE:     MIT (https://spdx.org/licenses/MIT)
4  * PURPOSE:     "Secure" shell path manipulation functions
5  * COPYRIGHT:   MinGW-64 and Microsoft Corporation.
6  */
7 
8 /**
9  * This file is part of the mingw-w64 runtime package.
10  * No warranty is given; refer to the file DISCLAIMER within this package.
11  */
12 
13 #pragma once
14 
15 
16 #ifndef WINBASEAPI
17 #ifndef _KERNEL32_
18 #define WINBASEAPI DECLSPEC_IMPORT
19 #else
20 #define WINBASEAPI
21 #endif
22 #endif
23 
24 
25 #ifndef WINPATHCCHAPI
26 #ifndef STATIC_PATHCCH
27 #define WINPATHCCHAPI WINBASEAPI
28 #else
29 #define WINPATHCCHAPI
30 #endif
31 #endif
32 
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 // typedef enum PATHCCH_OPTIONS
39 #define PATHCCH_NONE                            0x00
40 #define PATHCCH_ALLOW_LONG_PATHS                0x01
41 #define PATHCCH_FORCE_ENABLE_LONG_NAME_PROCESS  0x02
42 #define PATHCCH_FORCE_DISABLE_LONG_NAME_PROCESS 0x04
43 #define PATHCCH_DO_NOT_NORMALIZE_SEGMENTS       0x08
44 #define PATHCCH_ENSURE_IS_EXTENDED_LENGTH_PATH  0x10
45 #define PATHCCH_ENSURE_TRAILING_SLASH           0x20
46 // DEFINE_ENUM_FLAG_OPERATORS(PATHCCH_OPTIONS)
47 
48 #define VOLUME_PREFIX       L"\\\\?\\Volume"
49 #define VOLUME_PREFIX_LEN   (ARRAYSIZE(VOLUME_PREFIX) - 1)
50 
51 #define PATHCCH_MAX_CCH     0x8000
52 
53 WINPATHCCHAPI
54 HRESULT
55 APIENTRY
56 PathAllocCanonicalize(
57     _In_ PCWSTR pszPathIn,
58     _In_ /* PATHCCH_OPTIONS */ ULONG dwFlags,
59     _Outptr_ PWSTR* ppszPathOut);
60 
61 WINPATHCCHAPI
62 HRESULT
63 APIENTRY
64 PathAllocCombine(
65     _In_opt_ PCWSTR pszPathIn,
66     _In_opt_ PCWSTR pszMore,
67     _In_ /* PATHCCH_OPTIONS */ ULONG dwFlags,
68     _Outptr_ PWSTR* ppszPathOut);
69 
70 WINPATHCCHAPI
71 HRESULT
72 APIENTRY
73 PathCchAddBackslash(
74     _Inout_updates_(cchPath) PWSTR pszPath,
75     _In_ size_t cchPath);
76 
77 WINPATHCCHAPI
78 HRESULT
79 APIENTRY
80 PathCchAddBackslashEx(
81     _Inout_updates_(cchPath) PWSTR pszPath,
82     _In_ size_t cchPath,
83     _Outptr_opt_result_buffer_(*pcchRemaining) PWSTR* ppszEnd,
84     _Out_opt_ size_t* pcchRemaining);
85 
86 WINPATHCCHAPI
87 HRESULT
88 APIENTRY
89 PathCchAddExtension(
90     _Inout_updates_(cchPath) PWSTR pszPath,
91     _In_ size_t cchPath,
92     _In_ PCWSTR pszExt);
93 
94 WINPATHCCHAPI
95 HRESULT
96 APIENTRY
97 PathCchAppend(
98     _Inout_updates_(cchPath) PWSTR pszPath,
99     _In_ size_t cchPath,
100     _In_opt_ PCWSTR pszMore);
101 
102 WINPATHCCHAPI
103 HRESULT
104 APIENTRY
105 PathCchAppendEx(
106     _Inout_updates_(cchPath) PWSTR pszPath,
107     _In_ size_t cchPath,
108     _In_opt_ PCWSTR pszMore,
109     _In_ /* PATHCCH_OPTIONS */ ULONG dwFlags);
110 
111 WINPATHCCHAPI
112 HRESULT
113 APIENTRY
114 PathCchCanonicalize(
115     _Out_writes_(cchPathOut) PWSTR pszPathOut,
116     _In_ size_t cchPathOut,
117     _In_ PCWSTR pszPathIn);
118 
119 WINPATHCCHAPI
120 HRESULT
121 APIENTRY
122 PathCchCanonicalizeEx(
123     _Out_writes_(cchPathOut) PWSTR pszPathOut,
124     _In_ size_t cchPathOut,
125     _In_ PCWSTR pszPathIn,
126     _In_ /* PATHCCH_OPTIONS */ ULONG dwFlags);
127 
128 WINPATHCCHAPI
129 HRESULT
130 APIENTRY
131 PathCchCombine(
132     _Out_writes_(cchPathOut) PWSTR pszPathOut,
133     _In_ size_t cchPathOut,
134     _In_opt_ PCWSTR pszPathIn,
135     _In_opt_ PCWSTR pszMore);
136 
137 WINPATHCCHAPI
138 HRESULT
139 APIENTRY
140 PathCchCombineEx(
141     _Out_writes_(cchPathOut) PWSTR pszPathOut,
142     _In_ size_t cchPathOut,
143     _In_opt_ PCWSTR pszPathIn,
144     _In_opt_ PCWSTR pszMore,
145     _In_ /* PATHCCH_OPTIONS */ ULONG dwFlags);
146 
147 WINPATHCCHAPI
148 HRESULT
149 APIENTRY
150 PathCchFindExtension(
151     _In_reads_(cchPath) PCWSTR pszPath,
152     _In_ size_t cchPath,
153     _Outptr_ PCWSTR* ppszExt);
154 
155 WINPATHCCHAPI
156 BOOL
157 APIENTRY
158 PathCchIsRoot(
159     _In_opt_ PCWSTR pszPath);
160 
161 WINPATHCCHAPI
162 HRESULT
163 APIENTRY
164 PathCchRemoveBackslash(
165     _Inout_updates_(cchPath) PWSTR pszPath,
166     _In_ size_t cchPath);
167 
168 WINPATHCCHAPI
169 HRESULT
170 APIENTRY
171 PathCchRemoveBackslashEx(
172     _Inout_updates_(cchPath) PWSTR pszPath,
173     _In_ size_t cchPath,
174     _Outptr_opt_result_buffer_(*pcchRemaining) PWSTR* ppszEnd,
175     _Out_opt_ size_t* pcchRemaining);
176 
177 WINPATHCCHAPI
178 HRESULT
179 APIENTRY
180 PathCchRemoveExtension(
181     _Inout_updates_(cchPath) PWSTR pszPath,
182     _In_ size_t cchPath);
183 
184 WINPATHCCHAPI
185 HRESULT
186 APIENTRY
187 PathCchRemoveFileSpec(
188     _Inout_updates_(cchPath) PWSTR pszPath,
189     _In_ size_t cchPath);
190 
191 WINPATHCCHAPI
192 HRESULT
193 APIENTRY
194 PathCchRenameExtension(
195     _Inout_updates_(cchPath) PWSTR pszPath,
196     _In_ size_t cchPath,
197     _In_ PCWSTR pszExt);
198 
199 WINPATHCCHAPI
200 HRESULT
201 APIENTRY
202 PathCchSkipRoot(
203     _In_ PCWSTR pszPath,
204     _Outptr_ PCWSTR* ppszRootEnd);
205 
206 WINPATHCCHAPI
207 HRESULT
208 APIENTRY
209 PathCchStripPrefix(
210     _Inout_updates_(cchPath) PWSTR pszPath,
211     _In_ size_t cchPath);
212 
213 WINPATHCCHAPI
214 HRESULT
215 APIENTRY
216 PathCchStripToRoot(
217     _Inout_updates_(cchPath) PWSTR pszPath,
218     _In_ size_t cchPath);
219 
220 WINPATHCCHAPI
221 BOOL
222 APIENTRY
223 PathIsUNCEx(
224     _In_ PCWSTR pszPath,
225     _Outptr_opt_ PCWSTR* ppszServer);
226 
227 
228 #ifndef PATHCCH_NO_DEPRECATE
229 
230 #undef PathAddBackslash
231 #undef PathAddBackslashA
232 #undef PathAddBackslashW
233 
234 #undef PathAddExtension
235 #undef PathAddExtensionA
236 #undef PathAddExtensionW
237 
238 #undef PathAppend
239 #undef PathAppendA
240 #undef PathAppendW
241 
242 #undef PathCanonicalize
243 #undef PathCanonicalizeA
244 #undef PathCanonicalizeW
245 
246 #undef PathCombine
247 #undef PathCombineA
248 #undef PathCombineW
249 
250 #undef PathRenameExtension
251 #undef PathRenameExtensionA
252 #undef PathRenameExtensionW
253 
254 
255 #ifdef DEPRECATE_SUPPORTED
256 
257 // #pragma deprecated(PathIsRelativeWorker)
258 // #pragma deprecated(StrIsEqualWorker)
259 // #pragma deprecated(FindPreviousBackslashWorker)
260 // #pragma deprecated(IsHexDigitWorker)
261 // #pragma deprecated(StringIsGUIDWorker)
262 // #pragma deprecated(PathIsVolumeGUIDWorker)
263 // #pragma deprecated(IsValidExtensionWorker)
264 
265 #pragma deprecated(PathAddBackslash)
266 #pragma deprecated(PathAddBackslashA)
267 #pragma deprecated(PathAddBackslashW)
268 
269 #pragma deprecated(PathAddExtension)
270 #pragma deprecated(PathAddExtensionA)
271 #pragma deprecated(PathAddExtensionW)
272 
273 #pragma deprecated(PathAppend)
274 #pragma deprecated(PathAppendA)
275 #pragma deprecated(PathAppendW)
276 
277 #pragma deprecated(PathCanonicalize)
278 #pragma deprecated(PathCanonicalizeA)
279 #pragma deprecated(PathCanonicalizeW)
280 
281 #pragma deprecated(PathCombine)
282 #pragma deprecated(PathCombineA)
283 #pragma deprecated(PathCombineW)
284 
285 #pragma deprecated(PathRenameExtension)
286 #pragma deprecated(PathRenameExtensionA)
287 #pragma deprecated(PathRenameExtensionW)
288 
289 #else // !DEPRECATE_SUPPORTED
290 
291 // #define PathIsRelativeWorker    PathIsRelativeWorker_is_internal_to_pathcch;
292 // #define StrIsEqualWorker        StrIsEqualWorker_is_internal_to_pathcch;
293 // #define FindPreviousBackslashWorker FindPreviousBackslashWorker_is_internal_to_pathcch;
294 // #define IsHexDigitWorker        IsHexDigitWorker_is_internal_to_pathcch;
295 // #define StringIsGUIDWorker      StringIsGUIDWorker_is_internal_to_pathcch;
296 // #define PathIsVolumeGUIDWorker  PathIsVolumeGUIDWorker_is_internal_to_pathcch;
297 // #define IsValidExtensionWorker  IsValidExtensionWorker_is_internal_to_pathcch;
298 
299 #define PathAddBackslash        PathAddBackslash_instead_use_PathCchAddBackslash;
300 #define PathAddBackslashA       PathAddBackslash_instead_use_PathCchAddBackslash;
301 #define PathAddBackslashW       PathAddBackslash_instead_use_PathCchAddBackslash;
302 
303 #define PathAddExtension        PathAddExtension_instead_use_PathCchAddExtension;
304 #define PathAddExtensionA       PathAddExtension_instead_use_PathCchAddExtension;
305 #define PathAddExtensionW       PathAddExtension_instead_use_PathCchAddExtension;
306 
307 #define PathAppend              PathAppend_instead_use_PathCchAppend;
308 #define PathAppendA             PathAppend_instead_use_PathCchAppend;
309 #define PathAppendW             PathAppend_instead_use_PathCchAppend;
310 
311 #define PathCanonicalize        PathCanonicalize_instead_use_PathCchCanonicalize;
312 #define PathCanonicalizeA       PathCanonicalize_instead_use_PathCchCanonicalize;
313 #define PathCanonicalizeW       PathCanonicalize_instead_use_PathCchCanonicalize;
314 
315 #define PathCombine             PathCombine_instead_use_PathCchCombine;
316 #define PathCombineA            PathCombine_instead_use_PathCchCombine;
317 #define PathCombineW            PathCombine_instead_use_PathCchCombine;
318 
319 #define PathRenameExtension     PathRenameExtension_instead_use_PathCchRenameExtension;
320 #define PathRenameExtensionA    PathRenameExtension_instead_use_PathCchRenameExtension;
321 #define PathRenameExtensionW    PathRenameExtension_instead_use_PathCchRenameExtension;
322 
323 #endif // DEPRECATE_SUPPORTED
324 
325 #endif // PATHCCH_NO_DEPRECATE
326 
327 #ifdef __cplusplus
328 }
329 #endif
330 
331 
332 /* C++ non-const overloads */
333 #ifdef __cplusplus
334 
335 __inline HRESULT
PathCchFindExtension(_In_reads_ (cchPath)PWSTR pszPath,_In_ size_t cchPath,_Outptr_ PWSTR * ppszExt)336 PathCchFindExtension(
337     _In_reads_(cchPath) PWSTR pszPath,
338     _In_ size_t cchPath,
339     _Outptr_ PWSTR* ppszExt)
340 {
341     return PathCchFindExtension(const_cast<PCWSTR>(pszPath), cchPath, const_cast<PCWSTR*>(ppszExt));
342 }
343 
344 __inline HRESULT
PathCchSkipRoot(_In_ PWSTR pszPath,_Outptr_ PWSTR * ppszRootEnd)345 PathCchSkipRoot(
346     _In_ PWSTR pszPath,
347     _Outptr_ PWSTR* ppszRootEnd)
348 {
349     return PathCchSkipRoot(const_cast<PCWSTR>(pszPath), const_cast<PCWSTR*>(ppszRootEnd));
350 }
351 
352 __inline BOOL
PathIsUNCEx(_In_ PWSTR pszPath,_Outptr_opt_ PWSTR * ppszServer)353 PathIsUNCEx(
354     _In_ PWSTR pszPath,
355     _Outptr_opt_ PWSTR* ppszServer)
356 {
357     return PathIsUNCEx(const_cast<PCWSTR>(pszPath), const_cast<PCWSTR*>(ppszServer));
358 }
359 
360 #endif // __cplusplus
361