23#include <winpr/winpr.h>
24#include <winpr/tchar.h>
25#include <winpr/error.h>
26#include <winpr/wtypes.h>
30#ifdef WINPR_HAVE_PATHCCH_H
41#define PATHCCH_ALLOW_LONG_PATHS \
44#define VOLUME_PREFIX _T("\\\\?\\Volume")
45#define VOLUME_PREFIX_LEN ((sizeof(VOLUME_PREFIX) / sizeof(TCHAR)) - 1)
52#define PATHCCH_MAX_CCH 0x8000
54 WINPR_API HRESULT PathCchAddBackslashA(PSTR pszPath,
size_t cchPath);
55 WINPR_API HRESULT PathCchAddBackslashW(PWSTR pszPath,
size_t cchPath);
57 WINPR_API HRESULT PathCchRemoveBackslashA(PSTR pszPath,
size_t cchPath);
58 WINPR_API HRESULT PathCchRemoveBackslashW(PWSTR pszPath,
size_t cchPath);
60 WINPR_API HRESULT PathCchAddBackslashExA(PSTR pszPath,
size_t cchPath, PSTR* ppszEnd,
61 size_t* pcchRemaining);
62 WINPR_API HRESULT PathCchAddBackslashExW(PWSTR pszPath,
size_t cchPath, PWSTR* ppszEnd,
63 size_t* pcchRemaining);
65 WINPR_API HRESULT PathCchRemoveBackslashExA(PSTR pszPath,
size_t cchPath, PSTR* ppszEnd,
66 size_t* pcchRemaining);
67 WINPR_API HRESULT PathCchRemoveBackslashExW(PWSTR pszPath,
size_t cchPath, PWSTR* ppszEnd,
68 size_t* pcchRemaining);
70 WINPR_API HRESULT PathCchAddExtensionA(PSTR pszPath,
size_t cchPath, PCSTR pszExt);
71 WINPR_API HRESULT PathCchAddExtensionW(PWSTR pszPath,
size_t cchPath, PCWSTR pszExt);
73 WINPR_API HRESULT PathCchAppendA(PSTR pszPath,
size_t cchPath, PCSTR pszMore);
74 WINPR_API HRESULT PathCchAppendW(PWSTR pszPath,
size_t cchPath, PCWSTR pszMore);
76 WINPR_API HRESULT PathCchAppendExA(PSTR pszPath,
size_t cchPath, PCSTR pszMore,
77 unsigned long dwFlags);
78 WINPR_API HRESULT PathCchAppendExW(PWSTR pszPath,
size_t cchPath, PCWSTR pszMore,
79 unsigned long dwFlags);
81 WINPR_API HRESULT PathCchCanonicalizeA(PSTR pszPathOut,
size_t cchPathOut, PCSTR pszPathIn);
82 WINPR_API HRESULT PathCchCanonicalizeW(PWSTR pszPathOut,
size_t cchPathOut, PCWSTR pszPathIn);
84 WINPR_API HRESULT PathCchCanonicalizeExA(PSTR pszPathOut,
size_t cchPathOut, PCSTR pszPathIn,
85 unsigned long dwFlags);
86 WINPR_API HRESULT PathCchCanonicalizeExW(PWSTR pszPathOut,
size_t cchPathOut, PCWSTR pszPathIn,
87 unsigned long dwFlags);
89 WINPR_API HRESULT PathAllocCanonicalizeA(PCSTR pszPathIn,
unsigned long dwFlags,
91 WINPR_API HRESULT PathAllocCanonicalizeW(PCWSTR pszPathIn,
unsigned long dwFlags,
94 WINPR_API HRESULT PathCchCombineA(PSTR pszPathOut,
size_t cchPathOut, PCSTR pszPathIn,
96 WINPR_API HRESULT PathCchCombineW(PWSTR pszPathOut,
size_t cchPathOut, PCWSTR pszPathIn,
99 WINPR_API HRESULT PathCchCombineExA(PSTR pszPathOut,
size_t cchPathOut, PCSTR pszPathIn,
100 PCSTR pszMore,
unsigned long dwFlags);
101 WINPR_API HRESULT PathCchCombineExW(PWSTR pszPathOut,
size_t cchPathOut, PCWSTR pszPathIn,
102 PCWSTR pszMore,
unsigned long dwFlags);
104 WINPR_API HRESULT PathAllocCombineA(PCSTR pszPathIn, PCSTR pszMore,
unsigned long dwFlags,
106 WINPR_API HRESULT PathAllocCombineW(PCWSTR pszPathIn, PCWSTR pszMore,
unsigned long dwFlags,
109 WINPR_API HRESULT PathCchFindExtensionA(PCSTR pszPath,
size_t cchPath, PCSTR* ppszExt);
110 WINPR_API HRESULT PathCchFindExtensionW(PCWSTR pszPath,
size_t cchPath, PCWSTR* ppszExt);
112 WINPR_API HRESULT PathCchRenameExtensionA(PSTR pszPath,
size_t cchPath, PCSTR pszExt);
113 WINPR_API HRESULT PathCchRenameExtensionW(PWSTR pszPath,
size_t cchPath, PCWSTR pszExt);
115 WINPR_API HRESULT PathCchRemoveExtensionA(PSTR pszPath,
size_t cchPath);
116 WINPR_API HRESULT PathCchRemoveExtensionW(PWSTR pszPath,
size_t cchPath);
118 WINPR_API BOOL PathCchIsRootA(PCSTR pszPath);
119 WINPR_API BOOL PathCchIsRootW(PCWSTR pszPath);
121 WINPR_API BOOL PathIsUNCExA(PCSTR pszPath, PCSTR* ppszServer);
122 WINPR_API BOOL PathIsUNCExW(PCWSTR pszPath, PCWSTR* ppszServer);
124 WINPR_API HRESULT PathCchSkipRootA(PCSTR pszPath, PCSTR* ppszRootEnd);
125 WINPR_API HRESULT PathCchSkipRootW(PCWSTR pszPath, PCWSTR* ppszRootEnd);
127 WINPR_API HRESULT PathCchStripToRootA(PSTR pszPath,
size_t cchPath);
128 WINPR_API HRESULT PathCchStripToRootW(PWSTR pszPath,
size_t cchPath);
130 WINPR_API HRESULT PathCchStripPrefixA(PSTR pszPath,
size_t cchPath);
131 WINPR_API HRESULT PathCchStripPrefixW(PWSTR pszPath,
size_t cchPath);
133 WINPR_API HRESULT PathCchRemoveFileSpecA(PSTR pszPath,
size_t cchPath);
134 WINPR_API HRESULT PathCchRemoveFileSpecW(PWSTR pszPath,
size_t cchPath);
137#define PathCchAddBackslash PathCchAddBackslashW
138#define PathCchRemoveBackslash PathCchRemoveBackslashW
139#define PathCchAddBackslashEx PathCchAddBackslashExW
140#define PathCchRemoveBackslashEx PathCchRemoveBackslashExW
141#define PathCchAddExtension PathCchAddExtensionW
142#define PathCchAppend PathCchAppendW
143#define PathCchAppendEx PathCchAppendExW
144#define PathCchCanonicalize PathCchCanonicalizeW
145#define PathCchCanonicalizeEx PathCchCanonicalizeExW
146#define PathAllocCanonicalize PathAllocCanonicalizeW
147#define PathCchCombine PathCchCombineW
148#define PathCchCombineEx PathCchCombineExW
149#define PathAllocCombine PathAllocCombineW
150#define PathCchFindExtension PathCchFindExtensionW
151#define PathCchRenameExtension PathCchRenameExtensionW
152#define PathCchRemoveExtension PathCchRemoveExtensionW
153#define PathCchIsRoot PathCchIsRootW
154#define PathIsUNCEx PathIsUNCExW
155#define PathCchSkipRoot PathCchSkipRootW
156#define PathCchStripToRoot PathCchStripToRootW
157#define PathCchStripPrefix PathCchStripPrefixW
158#define PathCchRemoveFileSpec PathCchRemoveFileSpecW
160#define PathCchAddBackslash PathCchAddBackslashA
161#define PathCchRemoveBackslash PathCchRemoveBackslashA
162#define PathCchAddBackslashEx PathCchAddBackslashExA
163#define PathCchRemoveBackslashEx PathCchRemoveBackslashExA
164#define PathCchAddExtension PathCchAddExtensionA
165#define PathCchAppend PathCchAppendA
166#define PathCchAppendEx PathCchAppendExA
167#define PathCchCanonicalize PathCchCanonicalizeA
168#define PathCchCanonicalizeEx PathCchCanonicalizeExA
169#define PathAllocCanonicalize PathAllocCanonicalizeA
170#define PathCchCombine PathCchCombineA
171#define PathCchCombineEx PathCchCombineExA
172#define PathAllocCombine PathAllocCombineA
173#define PathCchFindExtension PathCchFindExtensionA
174#define PathCchRenameExtension PathCchRenameExtensionA
175#define PathCchRemoveExtension PathCchRemoveExtensionA
176#define PathCchIsRoot PathCchIsRootA
177#define PathIsUNCEx PathIsUNCExA
178#define PathCchSkipRoot PathCchSkipRootA
179#define PathCchStripToRoot PathCchStripToRootA
180#define PathCchStripPrefix PathCchStripPrefixA
181#define PathCchRemoveFileSpec PathCchRemoveFileSpecA
186 WINPR_API HRESULT PathCchAddSlashA(PSTR pszPath,
size_t cchPath);
187 WINPR_API HRESULT PathCchAddSlashW(PWSTR pszPath,
size_t cchPath);
189 WINPR_API HRESULT PathCchAddSlashExA(PSTR pszPath,
size_t cchPath, PSTR* ppszEnd,
190 size_t* pcchRemaining);
191 WINPR_API HRESULT PathCchAddSlashExW(PWSTR pszPath,
size_t cchPath, PWSTR* ppszEnd,
192 size_t* pcchRemaining);
194 WINPR_API HRESULT UnixPathCchAddExtensionA(PSTR pszPath,
size_t cchPath, PCSTR pszExt);
195 WINPR_API HRESULT UnixPathCchAddExtensionW(PWSTR pszPath,
size_t cchPath, PCWSTR pszExt);
197 WINPR_API HRESULT UnixPathCchAppendA(PSTR pszPath,
size_t cchPath, PCSTR pszMore);
198 WINPR_API HRESULT UnixPathCchAppendW(PWSTR pszPath,
size_t cchPath, PCWSTR pszMore);
200 WINPR_API HRESULT UnixPathAllocCombineA(PCSTR pszPathIn, PCSTR pszMore,
unsigned long dwFlags,
202 WINPR_API HRESULT UnixPathAllocCombineW(PCWSTR pszPathIn, PCWSTR pszMore,
unsigned long dwFlags,
206#define PathCchAddSlash PathCchAddSlashW
207#define PathCchAddSlashEx PathCchAddSlashExW
208#define UnixPathCchAddExtension UnixPathCchAddExtensionW
209#define UnixPathCchAppend UnixPathCchAppendW
210#define UnixPathAllocCombine UnixPathAllocCombineW
212#define PathCchAddSlash PathCchAddSlashA
213#define PathCchAddSlashEx PathCchAddSlashExA
214#define UnixPathCchAddExtension UnixPathCchAddExtensionA
215#define UnixPathCchAppend UnixPathCchAppendA
216#define UnixPathAllocCombine UnixPathAllocCombineA
221 WINPR_API HRESULT PathCchAddSeparatorA(PSTR pszPath,
size_t cchPath);
222 WINPR_API HRESULT PathCchAddSeparatorW(PWSTR pszPath,
size_t cchPath);
224 WINPR_API HRESULT PathCchAddSeparatorExA(PSTR pszPath,
size_t cchPath, PSTR* ppszEnd,
225 size_t* pcchRemaining);
226 WINPR_API HRESULT PathCchAddSeparatorExW(PWSTR pszPath,
size_t cchPath, PWSTR* ppszEnd,
227 size_t* pcchRemaining);
229 WINPR_API HRESULT NativePathCchAddExtensionA(PSTR pszPath,
size_t cchPath, PCSTR pszExt);
230 WINPR_API HRESULT NativePathCchAddExtensionW(PWSTR pszPath,
size_t cchPath, PCWSTR pszExt);
232 WINPR_API HRESULT NativePathCchAppendA(PSTR pszPath,
size_t cchPath, PCSTR pszMore);
233 WINPR_API HRESULT NativePathCchAppendW(PWSTR pszPath,
size_t cchPath, PCWSTR pszMore);
235 WINPR_API HRESULT NativePathAllocCombineA(PCSTR pszPathIn, PCSTR pszMore,
unsigned long dwFlags,
237 WINPR_API HRESULT NativePathAllocCombineW(PCWSTR pszPathIn, PCWSTR pszMore,
238 unsigned long dwFlags, PWSTR* ppszPathOut);
241#define PathCchAddSeparator PathCchAddSeparatorW
242#define PathCchAddSeparatorEx PathCchAddSeparatorExW
243#define NativePathCchAddExtension NativePathCchAddExtensionW
244#define NativePathCchAppend NativePathCchAppendW
245#define NativePathAllocCombine NativePathAllocCombineW
247#define PathCchAddSeparator PathCchAddSeparatorA
248#define PathCchAddSeparatorEx PathCchAddSeparatorExA
249#define NativePathCchAddExtension NativePathCchAddExtensionA
250#define NativePathCchAppend NativePathCchAppendA
251#define NativePathAllocCombine NativePathAllocCombineA
256#define PATH_STYLE_WINDOWS 0x00000001
257#define PATH_STYLE_UNIX 0x00000002
258#define PATH_STYLE_NATIVE 0x00000003
260#define PATH_SHARED_LIB_EXT_WITH_DOT 0x00000001
261#define PATH_SHARED_LIB_EXT_APPLE_SO 0x00000002
262#define PATH_SHARED_LIB_EXT_EXPLICIT 0x80000000
263#define PATH_SHARED_LIB_EXT_EXPLICIT_DLL 0x80000001
264#define PATH_SHARED_LIB_EXT_EXPLICIT_SO 0x80000002
265#define PATH_SHARED_LIB_EXT_EXPLICIT_DYLIB 0x80000003
267 WINPR_API HRESULT PathCchConvertStyleA(PSTR pszPath,
size_t cchPath,
unsigned long dwFlags);
268 WINPR_API HRESULT PathCchConvertStyleW(PWSTR pszPath,
size_t cchPath,
unsigned long dwFlags);
270 WINPR_API
char PathGetSeparatorA(
unsigned long dwFlags);
271 WINPR_API WCHAR PathGetSeparatorW(
unsigned long dwFlags);
273 WINPR_API PCSTR PathGetSharedLibraryExtensionA(
unsigned long dwFlags);
274 WINPR_API PCWSTR PathGetSharedLibraryExtensionW(
unsigned long dwFlags);
277#define PathCchConvertStyle PathCchConvertStyleW
278#define PathGetSeparator PathGetSeparatorW
279#define PathGetSharedLibraryExtension PathGetSharedLibraryExtensionW
281#define PathCchConvertStyle PathCchConvertStyleA
282#define PathGetSeparator PathGetSeparatorW
283#define PathGetSharedLibraryExtension PathGetSharedLibraryExtensionA
300 KNOWN_PATH_XDG_DATA_HOME = 3,
301 KNOWN_PATH_XDG_CONFIG_HOME = 4,
302 KNOWN_PATH_XDG_CACHE_HOME = 5,
303 KNOWN_PATH_XDG_RUNTIME_DIR = 6,
304 KNOWN_PATH_SYSTEM_CONFIG_HOME = 7
325 WINPR_ATTR_MALLOC(free, 1)
326 WINPR_API
char* winpr_GetConfigFilePath(BOOL system, const
char* filename);
328 WINPR_API const
char* GetKnownPathIdString(
int id);
330 WINPR_ATTR_MALLOC(free, 1)
331 WINPR_API
char* GetKnownPath(eKnownPathTypes
id);
333 WINPR_ATTR_MALLOC(free, 1)
334 WINPR_API
char* GetKnownSubPath(eKnownPathTypes
id, const
char* path);
336 WINPR_ATTR_MALLOC(free, 1)
337 WINPR_API
char* GetEnvironmentPath(
char* name);
339 WINPR_ATTR_MALLOC(free, 1)
340 WINPR_API
char* GetEnvironmentSubPath(
char* name, const
char* path);
342 WINPR_ATTR_MALLOC(free, 1)
343 WINPR_API
char* GetCombinedPath(const
char* basePath, const
char* subPath);
345 WINPR_API BOOL PathMakePathA(LPCSTR path, LPSECURITY_ATTRIBUTES lpAttributes);
346 WINPR_API BOOL PathMakePathW(LPCWSTR path, LPSECURITY_ATTRIBUTES lpAttributes);
348#if !defined(_WIN32) || defined(_UWP)
350 WINPR_API BOOL PathIsRelativeA(LPCSTR pszPath);
351 WINPR_API BOOL PathIsRelativeW(LPCWSTR pszPath);
353 WINPR_API BOOL PathFileExistsA(LPCSTR pszPath);
354 WINPR_API BOOL PathFileExistsW(LPCWSTR pszPath);
356 WINPR_API BOOL PathIsDirectoryEmptyA(LPCSTR pszPath);
357 WINPR_API BOOL PathIsDirectoryEmptyW(LPCWSTR pszPath);
360#define PathFileExists PathFileExistsW
361#define PathIsDirectoryEmpty PathIsDirectoryEmptyW
363#define PathFileExists PathFileExistsA
364#define PathIsDirectoryEmpty PathIsDirectoryEmptyA
369 WINPR_API BOOL winpr_MoveFile(LPCSTR lpExistingFileName, LPCSTR lpNewFileName);
370 WINPR_API BOOL winpr_MoveFileEx(LPCSTR lpExistingFileName, LPCSTR lpNewFileName, DWORD dwFlags);
371 WINPR_API BOOL winpr_DeleteFile(
const char* lpFileName);
372 WINPR_API BOOL winpr_RemoveDirectory(LPCSTR lpPathName);
373 WINPR_API BOOL winpr_RemoveDirectory_RecursiveA(LPCSTR lpPathName);
374 WINPR_API BOOL winpr_RemoveDirectory_RecursiveW(LPCWSTR lpPathName);
375 WINPR_API BOOL winpr_PathFileExists(
const char* pszPath);
376 WINPR_API BOOL winpr_PathMakePath(
const char* path, LPSECURITY_ATTRIBUTES lpAttributes);