2
* WinPR: Windows Portable Runtime
5
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7
* Licensed under the Apache License, Version 2.0 (the "License");
8
* you may not use this file except in compliance with the License.
9
* You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
23
#include <winpr/winpr.h>
24
#include <winpr/tchar.h>
25
#include <winpr/error.h>
26
#include <winpr/wtypes.h>
28
//#define HAVE_PATHCCH_H 1
40
#define PATHCCH_ALLOW_LONG_PATHS 0x00000001 /* Allow building of \\?\ paths if longer than MAX_PATH */
42
#define VOLUME_PREFIX _T("\\\\?\\Volume")
43
#define VOLUME_PREFIX_LEN ((sizeof(VOLUME_PREFIX) / sizeof(TCHAR)) - 1)
46
* Maximum number of characters we support using the "\\?\" syntax
47
* (0x7FFF + 1 for NULL terminator)
50
#define PATHCCH_MAX_CCH 0x8000
52
WINPR_API HRESULT PathCchAddBackslashA(PSTR pszPath, size_t cchPath);
53
WINPR_API HRESULT PathCchAddBackslashW(PWSTR pszPath, size_t cchPath);
55
WINPR_API HRESULT PathCchRemoveBackslashA(PSTR pszPath, size_t cchPath);
56
WINPR_API HRESULT PathCchRemoveBackslashW(PWSTR pszPath, size_t cchPath);
58
WINPR_API HRESULT PathCchAddBackslashExA(PSTR pszPath, size_t cchPath, PSTR* ppszEnd, size_t* pcchRemaining);
59
WINPR_API HRESULT PathCchAddBackslashExW(PWSTR pszPath, size_t cchPath, PWSTR* ppszEnd, size_t* pcchRemaining);
61
WINPR_API HRESULT PathCchRemoveBackslashExA(PSTR pszPath, size_t cchPath, PSTR* ppszEnd, size_t* pcchRemaining);
62
WINPR_API HRESULT PathCchRemoveBackslashExW(PWSTR pszPath, size_t cchPath, PWSTR* ppszEnd, size_t* pcchRemaining);
64
WINPR_API HRESULT PathCchAddExtensionA(PSTR pszPath, size_t cchPath, PCSTR pszExt);
65
WINPR_API HRESULT PathCchAddExtensionW(PWSTR pszPath, size_t cchPath, PCWSTR pszExt);
67
WINPR_API HRESULT PathCchAppendA(PSTR pszPath, size_t cchPath, PCSTR pszMore);
68
WINPR_API HRESULT PathCchAppendW(PWSTR pszPath, size_t cchPath, PCWSTR pszMore);
70
WINPR_API HRESULT PathCchAppendExA(PSTR pszPath, size_t cchPath, PCSTR pszMore, unsigned long dwFlags);
71
WINPR_API HRESULT PathCchAppendExW(PWSTR pszPath, size_t cchPath, PCWSTR pszMore, unsigned long dwFlags);
73
WINPR_API HRESULT PathCchCanonicalizeA(PSTR pszPathOut, size_t cchPathOut, PCSTR pszPathIn);
74
WINPR_API HRESULT PathCchCanonicalizeW(PWSTR pszPathOut, size_t cchPathOut, PCWSTR pszPathIn);
76
WINPR_API HRESULT PathCchCanonicalizeExA(PSTR pszPathOut, size_t cchPathOut, PCSTR pszPathIn, unsigned long dwFlags);
77
WINPR_API HRESULT PathCchCanonicalizeExW(PWSTR pszPathOut, size_t cchPathOut, PCWSTR pszPathIn, unsigned long dwFlags);
79
WINPR_API HRESULT PathAllocCanonicalizeA(PCSTR pszPathIn, unsigned long dwFlags, PSTR* ppszPathOut);
80
WINPR_API HRESULT PathAllocCanonicalizeW(PCWSTR pszPathIn, unsigned long dwFlags, PWSTR* ppszPathOut);
82
WINPR_API HRESULT PathCchCombineA(PSTR pszPathOut, size_t cchPathOut, PCSTR pszPathIn, PCSTR pszMore);
83
WINPR_API HRESULT PathCchCombineW(PWSTR pszPathOut, size_t cchPathOut, PCWSTR pszPathIn, PCWSTR pszMore);
85
WINPR_API HRESULT PathCchCombineExA(PSTR pszPathOut, size_t cchPathOut, PCSTR pszPathIn, PCSTR pszMore, unsigned long dwFlags);
86
WINPR_API HRESULT PathCchCombineExW(PWSTR pszPathOut, size_t cchPathOut, PCWSTR pszPathIn, PCWSTR pszMore, unsigned long dwFlags);
88
WINPR_API HRESULT PathAllocCombineA(PCSTR pszPathIn, PCSTR pszMore, unsigned long dwFlags, PSTR* ppszPathOut);
89
WINPR_API HRESULT PathAllocCombineW(PCWSTR pszPathIn, PCWSTR pszMore, unsigned long dwFlags, PWSTR* ppszPathOut);
91
WINPR_API HRESULT PathCchFindExtensionA(PCSTR pszPath, size_t cchPath, PCSTR* ppszExt);
92
WINPR_API HRESULT PathCchFindExtensionW(PCWSTR pszPath, size_t cchPath, PCWSTR* ppszExt);
94
WINPR_API HRESULT PathCchRenameExtensionA(PSTR pszPath, size_t cchPath, PCSTR pszExt);
95
WINPR_API HRESULT PathCchRenameExtensionW(PWSTR pszPath, size_t cchPath, PCWSTR pszExt);
97
WINPR_API HRESULT PathCchRemoveExtensionA(PSTR pszPath, size_t cchPath);
98
WINPR_API HRESULT PathCchRemoveExtensionW(PWSTR pszPath, size_t cchPath);
100
WINPR_API BOOL PathCchIsRootA(PCSTR pszPath);
101
WINPR_API BOOL PathCchIsRootW(PCWSTR pszPath);
103
WINPR_API BOOL PathIsUNCExA(PCSTR pszPath, PCSTR* ppszServer);
104
WINPR_API BOOL PathIsUNCExW(PCWSTR pszPath, PCWSTR* ppszServer);
106
WINPR_API HRESULT PathCchSkipRootA(PCSTR pszPath, PCSTR* ppszRootEnd);
107
WINPR_API HRESULT PathCchSkipRootW(PCWSTR pszPath, PCWSTR* ppszRootEnd);
109
WINPR_API HRESULT PathCchStripToRootA(PSTR pszPath, size_t cchPath);
110
WINPR_API HRESULT PathCchStripToRootW(PWSTR pszPath, size_t cchPath);
112
WINPR_API HRESULT PathCchStripPrefixA(PSTR pszPath, size_t cchPath);
113
WINPR_API HRESULT PathCchStripPrefixW(PWSTR pszPath, size_t cchPath);
115
WINPR_API HRESULT PathCchRemoveFileSpecA(PSTR pszPath, size_t cchPath);
116
WINPR_API HRESULT PathCchRemoveFileSpecW(PWSTR pszPath, size_t cchPath);
120
#define PathCchAddBackslash PathCchAddBackslashW
121
#define PathCchRemoveBackslash PathCchRemoveBackslashW
122
#define PathCchAddBackslashEx PathCchAddBackslashExW
123
#define PathCchRemoveBackslashEx PathCchRemoveBackslashExW
124
#define PathCchAddExtension PathCchAddExtensionW
125
#define PathCchAppend PathCchAppendW
126
#define PathCchAppendEx PathCchAppendExW
127
#define PathCchCanonicalize PathCchCanonicalizeW
128
#define PathCchCanonicalizeEx PathCchCanonicalizeExW
129
#define PathAllocCanonicalize PathAllocCanonicalizeW
130
#define PathCchCombine PathCchCombineW
131
#define PathCchCombineEx PathCchCombineExW
132
#define PathAllocCombine PathAllocCombineW
133
#define PathCchFindExtension PathCchFindExtensionW
134
#define PathCchRenameExtension PathCchRenameExtensionW
135
#define PathCchRemoveExtension PathCchRemoveExtensionW
136
#define PathCchIsRoot PathCchIsRootW
137
#define PathIsUNCEx PathIsUNCExW
138
#define PathCchSkipRoot PathCchSkipRootW
139
#define PathCchStripToRoot PathCchStripToRootW
140
#define PathCchStripPrefix PathCchStripPrefixW
141
#define PathCchRemoveFileSpec PathCchRemoveFileSpecW
143
#define PathCchAddBackslash PathCchAddBackslashA
144
#define PathCchRemoveBackslash PathCchRemoveBackslashA
145
#define PathCchAddBackslashEx PathCchAddBackslashExA
146
#define PathCchRemoveBackslashEx PathCchRemoveBackslashExA
147
#define PathCchAddExtension PathCchAddExtensionA
148
#define PathCchAppend PathCchAppendA
149
#define PathCchAppendEx PathCchAppendExA
150
#define PathCchCanonicalize PathCchCanonicalizeA
151
#define PathCchCanonicalizeEx PathCchCanonicalizeExA
152
#define PathAllocCanonicalize PathAllocCanonicalizeA
153
#define PathCchCombine PathCchCombineA
154
#define PathCchCombineEx PathCchCombineExA
155
#define PathAllocCombine PathAllocCombineA
156
#define PathCchFindExtension PathCchFindExtensionA
157
#define PathCchRenameExtension PathCchRenameExtensionA
158
#define PathCchRemoveExtension PathCchRemoveExtensionA
159
#define PathCchIsRoot PathCchIsRootA
160
#define PathIsUNCEx PathIsUNCExA
161
#define PathCchSkipRoot PathCchSkipRootA
162
#define PathCchStripToRoot PathCchStripToRootA
163
#define PathCchStripPrefix PathCchStripPrefixA
164
#define PathCchRemoveFileSpec PathCchRemoveFileSpecA
167
/* Unix-style Paths */
169
WINPR_API HRESULT PathCchAddSlashA(PSTR pszPath, size_t cchPath);
170
WINPR_API HRESULT PathCchAddSlashW(PWSTR pszPath, size_t cchPath);
172
WINPR_API HRESULT PathCchAddSlashExA(PSTR pszPath, size_t cchPath, PSTR* ppszEnd, size_t* pcchRemaining);
173
WINPR_API HRESULT PathCchAddSlashExW(PWSTR pszPath, size_t cchPath, PWSTR* ppszEnd, size_t* pcchRemaining);
175
WINPR_API HRESULT UnixPathCchAddExtensionA(PSTR pszPath, size_t cchPath, PCSTR pszExt);
176
WINPR_API HRESULT UnixPathCchAddExtensionW(PWSTR pszPath, size_t cchPath, PCWSTR pszExt);
178
WINPR_API HRESULT UnixPathCchAppendA(PSTR pszPath, size_t cchPath, PCSTR pszMore);
179
WINPR_API HRESULT UnixPathCchAppendW(PWSTR pszPath, size_t cchPath, PCWSTR pszMore);
181
WINPR_API HRESULT UnixPathAllocCombineA(PCSTR pszPathIn, PCSTR pszMore, unsigned long dwFlags, PSTR* ppszPathOut);
182
WINPR_API HRESULT UnixPathAllocCombineW(PCWSTR pszPathIn, PCWSTR pszMore, unsigned long dwFlags, PWSTR* ppszPathOut);
185
#define PathCchAddSlash PathCchAddSlashW
186
#define PathCchAddSlashEx PathCchAddSlashExW
187
#define UnixPathCchAddExtension UnixPathCchAddExtensionW
188
#define UnixPathCchAppend UnixPathCchAppendW
189
#define UnixPathAllocCombine UnixPathAllocCombineW
191
#define PathCchAddSlash PathCchAddSlashA
192
#define PathCchAddSlashEx PathCchAddSlashExA
193
#define UnixPathCchAddExtension UnixPathCchAddExtensionA
194
#define UnixPathCchAppend UnixPathCchAppendA
195
#define UnixPathAllocCombine UnixPathAllocCombineA
198
/* Native-style Paths */
200
WINPR_API HRESULT PathCchAddSeparatorA(PSTR pszPath, size_t cchPath);
201
WINPR_API HRESULT PathCchAddSeparatorW(PWSTR pszPath, size_t cchPath);
203
WINPR_API HRESULT PathCchAddSeparatorExA(PSTR pszPath, size_t cchPath, PSTR* ppszEnd, size_t* pcchRemaining);
204
WINPR_API HRESULT PathCchAddSeparatorExW(PWSTR pszPath, size_t cchPath, PWSTR* ppszEnd, size_t* pcchRemaining);
206
WINPR_API HRESULT NativePathCchAddExtensionA(PSTR pszPath, size_t cchPath, PCSTR pszExt);
207
WINPR_API HRESULT NativePathCchAddExtensionW(PWSTR pszPath, size_t cchPath, PCWSTR pszExt);
209
WINPR_API HRESULT NativePathCchAppendA(PSTR pszPath, size_t cchPath, PCSTR pszMore);
210
WINPR_API HRESULT NativePathCchAppendW(PWSTR pszPath, size_t cchPath, PCWSTR pszMore);
212
WINPR_API HRESULT NativePathAllocCombineA(PCSTR pszPathIn, PCSTR pszMore, unsigned long dwFlags, PSTR* ppszPathOut);
213
WINPR_API HRESULT NativePathAllocCombineW(PCWSTR pszPathIn, PCWSTR pszMore, unsigned long dwFlags, PWSTR* ppszPathOut);
216
#define PathCchAddSeparator PathCchAddSeparatorW
217
#define PathCchAddSeparatorEx PathCchAddSeparatorExW
218
#define NativePathCchAddExtension NativePathCchAddExtensionW
219
#define NativePathCchAppend NativePathCchAppendW
220
#define NativePathAllocCombine NativePathAllocCombineW
222
#define PathCchAddSeparator PathCchAddSeparatorA
223
#define PathCchAddSeparatorEx PathCchAddSeparatorExA
224
#define NativePathCchAddExtension NativePathCchAddExtensionA
225
#define NativePathCchAppend NativePathCchAppendA
226
#define NativePathAllocCombine NativePathAllocCombineA
229
/* Path Portability Functions */
231
#define PATH_STYLE_WINDOWS 0x00000001
232
#define PATH_STYLE_UNIX 0x00000002
233
#define PATH_STYLE_NATIVE 0x00000003
235
#define PATH_SHARED_LIB_EXT_WITH_DOT 0x00000001
236
#define PATH_SHARED_LIB_EXT_APPLE_SO 0x00000002
237
#define PATH_SHARED_LIB_EXT_EXPLICIT 0x80000000
238
#define PATH_SHARED_LIB_EXT_EXPLICIT_DLL 0x80000001
239
#define PATH_SHARED_LIB_EXT_EXPLICIT_SO 0x80000002
240
#define PATH_SHARED_LIB_EXT_EXPLICIT_DYLIB 0x80000003
242
WINPR_API HRESULT PathCchConvertStyleA(PSTR pszPath, size_t cchPath, unsigned long dwFlags);
243
WINPR_API HRESULT PathCchConvertStyleW(PWSTR pszPath, size_t cchPath, unsigned long dwFlags);
245
WINPR_API PCSTR PathGetSharedLibraryExtensionA(unsigned long dwFlags);
246
WINPR_API PCWSTR PathGetSharedLibraryExtensionW(unsigned long dwFlags);
249
#define PathCchConvertStyle PathCchConvertStyleW
250
#define PathGetSharedLibraryExtension PathGetSharedLibraryExtensionW
252
#define PathCchConvertStyle PathCchConvertStyleA
253
#define PathGetSharedLibraryExtension PathGetSharedLibraryExtensionA
263
* Shell Path Functions
266
#define KNOWN_PATH_HOME 1
267
#define KNOWN_PATH_TEMP 2
268
#define KNOWN_PATH_XDG_DATA_HOME 3
269
#define KNOWN_PATH_XDG_CONFIG_HOME 4
270
#define KNOWN_PATH_XDG_CACHE_HOME 5
271
#define KNOWN_PATH_XDG_RUNTIME_DIR 6
277
WINPR_API char* GetKnownPath(int id);
278
WINPR_API char* GetKnownSubPath(int id, char* path);
279
WINPR_API char* GetCombinedPath(char* basePath, char* subPath);
283
WINPR_API BOOL PathFileExistsA(LPCSTR pszPath);
284
WINPR_API BOOL PathFileExistsW(LPCWSTR pszPath);
291
#define PathFileExists PathFileExistsW
293
#define PathFileExists PathFileExistsA
298
#endif /* WINPR_PATH_H */