20 #include <winpr/config.h>
21 #include <winpr/version.h>
22 #include <winpr/build-config.h>
24 #include <winpr/crt.h>
25 #include <winpr/tchar.h>
27 #include <winpr/path.h>
28 #include <winpr/file.h>
32 #define PATH_SLASH_CHR '/'
33 #define PATH_SLASH_STR "/"
35 #define PATH_BACKSLASH_CHR '\\'
36 #define PATH_BACKSLASH_STR "\\"
39 #define PATH_SLASH_STR_W L"/"
40 #define PATH_BACKSLASH_STR_W L"\\"
42 #define PATH_SLASH_STR_W \
46 #define PATH_BACKSLASH_STR_W \
53 #define PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
54 #define PATH_SEPARATOR_STR PATH_BACKSLASH_STR
55 #define PATH_SEPARATOR_STR_W PATH_BACKSLASH_STR_W
57 #define PATH_SEPARATOR_CHR PATH_SLASH_CHR
58 #define PATH_SEPARATOR_STR PATH_SLASH_STR
59 #define PATH_SEPARATOR_STR_W PATH_SLASH_STR_W
62 #define SHARED_LIBRARY_EXT_DLL "dll"
63 #define SHARED_LIBRARY_EXT_SO "so"
64 #define SHARED_LIBRARY_EXT_DYLIB "dylib"
67 #define SHARED_LIBRARY_EXT SHARED_LIBRARY_EXT_DLL
68 #elif defined(__APPLE__)
69 #define SHARED_LIBRARY_EXT SHARED_LIBRARY_EXT_DYLIB
71 #define SHARED_LIBRARY_EXT SHARED_LIBRARY_EXT_SO
75 #define TAG WINPR_TAG("path")
83 #define DEFINE_UNICODE FALSE
84 #define CUR_PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
85 #define PATH_CCH_ADD_SEPARATOR PathCchAddBackslashA
86 #include "include/PathCchAddSeparator.h"
88 #undef CUR_PATH_SEPARATOR_CHR
89 #undef PATH_CCH_ADD_SEPARATOR
91 #define DEFINE_UNICODE TRUE
92 #define CUR_PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
93 #define PATH_CCH_ADD_SEPARATOR PathCchAddBackslashW
94 #include "include/PathCchAddSeparator.h"
96 #undef CUR_PATH_SEPARATOR_CHR
97 #undef PATH_CCH_ADD_SEPARATOR
101 #define DEFINE_UNICODE FALSE
102 #define CUR_PATH_SEPARATOR_CHR PATH_SLASH_CHR
103 #define PATH_CCH_ADD_SEPARATOR PathCchAddSlashA
104 #include "include/PathCchAddSeparator.h"
105 #undef DEFINE_UNICODE
106 #undef CUR_PATH_SEPARATOR_CHR
107 #undef PATH_CCH_ADD_SEPARATOR
109 #define DEFINE_UNICODE TRUE
110 #define CUR_PATH_SEPARATOR_CHR PATH_SLASH_CHR
111 #define PATH_CCH_ADD_SEPARATOR PathCchAddSlashW
112 #include "include/PathCchAddSeparator.h"
113 #undef DEFINE_UNICODE
114 #undef CUR_PATH_SEPARATOR_CHR
115 #undef PATH_CCH_ADD_SEPARATOR
119 #define DEFINE_UNICODE FALSE
120 #define CUR_PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
121 #define PATH_CCH_ADD_SEPARATOR PathCchAddSeparatorA
122 #include "include/PathCchAddSeparator.h"
123 #undef DEFINE_UNICODE
124 #undef CUR_PATH_SEPARATOR_CHR
125 #undef PATH_CCH_ADD_SEPARATOR
127 #define DEFINE_UNICODE TRUE
128 #define CUR_PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
129 #define PATH_CCH_ADD_SEPARATOR PathCchAddSeparatorW
130 #include "include/PathCchAddSeparator.h"
131 #undef DEFINE_UNICODE
132 #undef CUR_PATH_SEPARATOR_CHR
133 #undef PATH_CCH_ADD_SEPARATOR
139 HRESULT PathCchRemoveBackslashA(PSTR pszPath,
size_t cchPath)
141 WLog_ERR(TAG,
"not implemented");
145 HRESULT PathCchRemoveBackslashW(PWSTR pszPath,
size_t cchPath)
147 WLog_ERR(TAG,
"not implemented");
157 #define DEFINE_UNICODE FALSE
158 #define CUR_PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
159 #define PATH_CCH_ADD_SEPARATOR_EX PathCchAddBackslashExA
160 #include "include/PathCchAddSeparatorEx.h"
161 #undef DEFINE_UNICODE
162 #undef CUR_PATH_SEPARATOR_CHR
163 #undef PATH_CCH_ADD_SEPARATOR_EX
165 #define DEFINE_UNICODE TRUE
166 #define CUR_PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
167 #define PATH_CCH_ADD_SEPARATOR_EX PathCchAddBackslashExW
168 #include "include/PathCchAddSeparatorEx.h"
169 #undef DEFINE_UNICODE
170 #undef CUR_PATH_SEPARATOR_CHR
171 #undef PATH_CCH_ADD_SEPARATOR_EX
175 #define DEFINE_UNICODE FALSE
176 #define CUR_PATH_SEPARATOR_CHR PATH_SLASH_CHR
177 #define PATH_CCH_ADD_SEPARATOR_EX PathCchAddSlashExA
178 #include "include/PathCchAddSeparatorEx.h"
179 #undef DEFINE_UNICODE
180 #undef CUR_PATH_SEPARATOR_CHR
181 #undef PATH_CCH_ADD_SEPARATOR_EX
183 #define DEFINE_UNICODE TRUE
184 #define CUR_PATH_SEPARATOR_CHR PATH_SLASH_CHR
185 #define PATH_CCH_ADD_SEPARATOR_EX PathCchAddSlashExW
186 #include "include/PathCchAddSeparatorEx.h"
187 #undef DEFINE_UNICODE
188 #undef CUR_PATH_SEPARATOR_CHR
189 #undef PATH_CCH_ADD_SEPARATOR_EX
193 #define DEFINE_UNICODE FALSE
194 #define CUR_PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
195 #define PATH_CCH_ADD_SEPARATOR_EX PathCchAddSeparatorExA
196 #include "include/PathCchAddSeparatorEx.h"
197 #undef DEFINE_UNICODE
198 #undef CUR_PATH_SEPARATOR_CHR
199 #undef PATH_CCH_ADD_SEPARATOR_EX
201 #define DEFINE_UNICODE TRUE
202 #define CUR_PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
203 #define PATH_CCH_ADD_SEPARATOR_EX PathCchAddSeparatorExW
204 #include "include/PathCchAddSeparatorEx.h"
205 #undef DEFINE_UNICODE
206 #undef CUR_PATH_SEPARATOR_CHR
207 #undef PATH_CCH_ADD_SEPARATOR_EX
209 HRESULT PathCchRemoveBackslashExA(PSTR pszPath,
size_t cchPath, PSTR* ppszEnd,
210 size_t* pcchRemaining)
212 WLog_ERR(TAG,
"not implemented");
216 HRESULT PathCchRemoveBackslashExW(PWSTR pszPath,
size_t cchPath, PWSTR* ppszEnd,
217 size_t* pcchRemaining)
219 WLog_ERR(TAG,
"not implemented");
229 #define DEFINE_UNICODE FALSE
230 #define CUR_PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
231 #define PATH_CCH_ADD_EXTENSION PathCchAddExtensionA
232 #include "include/PathCchAddExtension.h"
233 #undef DEFINE_UNICODE
234 #undef CUR_PATH_SEPARATOR_CHR
235 #undef PATH_CCH_ADD_EXTENSION
237 #define DEFINE_UNICODE TRUE
238 #define CUR_PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
239 #define PATH_CCH_ADD_EXTENSION PathCchAddExtensionW
240 #include "include/PathCchAddExtension.h"
241 #undef DEFINE_UNICODE
242 #undef CUR_PATH_SEPARATOR_CHR
243 #undef PATH_CCH_ADD_EXTENSION
247 #define DEFINE_UNICODE FALSE
248 #define CUR_PATH_SEPARATOR_CHR PATH_SLASH_CHR
249 #define PATH_CCH_ADD_EXTENSION UnixPathCchAddExtensionA
250 #include "include/PathCchAddExtension.h"
251 #undef DEFINE_UNICODE
252 #undef CUR_PATH_SEPARATOR_CHR
253 #undef PATH_CCH_ADD_EXTENSION
255 #define DEFINE_UNICODE TRUE
256 #define CUR_PATH_SEPARATOR_CHR PATH_SLASH_CHR
257 #define PATH_CCH_ADD_EXTENSION UnixPathCchAddExtensionW
258 #include "include/PathCchAddExtension.h"
259 #undef DEFINE_UNICODE
260 #undef CUR_PATH_SEPARATOR_CHR
261 #undef PATH_CCH_ADD_EXTENSION
265 #define DEFINE_UNICODE FALSE
266 #define CUR_PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
267 #define PATH_CCH_ADD_EXTENSION NativePathCchAddExtensionA
268 #include "include/PathCchAddExtension.h"
269 #undef DEFINE_UNICODE
270 #undef CUR_PATH_SEPARATOR_CHR
271 #undef PATH_CCH_ADD_EXTENSION
273 #define DEFINE_UNICODE TRUE
274 #define CUR_PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
275 #define PATH_CCH_ADD_EXTENSION NativePathCchAddExtensionW
276 #include "include/PathCchAddExtension.h"
277 #undef DEFINE_UNICODE
278 #undef CUR_PATH_SEPARATOR_CHR
279 #undef PATH_CCH_ADD_EXTENSION
287 #define DEFINE_UNICODE FALSE
288 #define CUR_PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
289 #define CUR_PATH_SEPARATOR_STR PATH_BACKSLASH_STR
290 #define PATH_CCH_APPEND PathCchAppendA
291 #include "include/PathCchAppend.h"
292 #undef DEFINE_UNICODE
293 #undef CUR_PATH_SEPARATOR_CHR
294 #undef CUR_PATH_SEPARATOR_STR
295 #undef PATH_CCH_APPEND
297 #define DEFINE_UNICODE TRUE
298 #define CUR_PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
299 #define CUR_PATH_SEPARATOR_STR PATH_BACKSLASH_STR_W
300 #define PATH_CCH_APPEND PathCchAppendW
301 #include "include/PathCchAppend.h"
302 #undef DEFINE_UNICODE
303 #undef CUR_PATH_SEPARATOR_CHR
304 #undef CUR_PATH_SEPARATOR_STR
305 #undef PATH_CCH_APPEND
309 #define DEFINE_UNICODE FALSE
310 #define CUR_PATH_SEPARATOR_CHR PATH_SLASH_CHR
311 #define CUR_PATH_SEPARATOR_STR PATH_SLASH_STR
312 #define PATH_CCH_APPEND UnixPathCchAppendA
313 #include "include/PathCchAppend.h"
314 #undef DEFINE_UNICODE
315 #undef CUR_PATH_SEPARATOR_CHR
316 #undef CUR_PATH_SEPARATOR_STR
317 #undef PATH_CCH_APPEND
319 #define DEFINE_UNICODE TRUE
320 #define CUR_PATH_SEPARATOR_CHR PATH_SLASH_CHR
321 #define CUR_PATH_SEPARATOR_STR PATH_SLASH_STR_W
322 #define PATH_CCH_APPEND UnixPathCchAppendW
323 #include "include/PathCchAppend.h"
324 #undef DEFINE_UNICODE
325 #undef CUR_PATH_SEPARATOR_CHR
326 #undef CUR_PATH_SEPARATOR_STR
327 #undef PATH_CCH_APPEND
331 #define DEFINE_UNICODE FALSE
332 #define CUR_PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
333 #define CUR_PATH_SEPARATOR_STR PATH_SEPARATOR_STR
334 #define PATH_CCH_APPEND NativePathCchAppendA
335 #include "include/PathCchAppend.h"
336 #undef DEFINE_UNICODE
337 #undef CUR_PATH_SEPARATOR_CHR
338 #undef CUR_PATH_SEPARATOR_STR
339 #undef PATH_CCH_APPEND
341 #define DEFINE_UNICODE TRUE
342 #define CUR_PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
343 #define CUR_PATH_SEPARATOR_STR PATH_SEPARATOR_STR_W
344 #define PATH_CCH_APPEND NativePathCchAppendW
345 #include "include/PathCchAppend.h"
346 #undef DEFINE_UNICODE
347 #undef CUR_PATH_SEPARATOR_CHR
348 #undef CUR_PATH_SEPARATOR_STR
349 #undef PATH_CCH_APPEND
355 HRESULT PathCchAppendExA(PSTR pszPath,
size_t cchPath, PCSTR pszMore,
unsigned long dwFlags)
357 WLog_ERR(TAG,
"not implemented");
361 HRESULT PathCchAppendExW(PWSTR pszPath,
size_t cchPath, PCWSTR pszMore,
unsigned long dwFlags)
363 WLog_ERR(TAG,
"not implemented");
371 HRESULT PathCchCanonicalizeA(PSTR pszPathOut,
size_t cchPathOut, PCSTR pszPathIn)
373 WLog_ERR(TAG,
"not implemented");
377 HRESULT PathCchCanonicalizeW(PWSTR pszPathOut,
size_t cchPathOut, PCWSTR pszPathIn)
379 WLog_ERR(TAG,
"not implemented");
387 HRESULT PathCchCanonicalizeExA(PSTR pszPathOut,
size_t cchPathOut, PCSTR pszPathIn,
388 unsigned long dwFlags)
390 WLog_ERR(TAG,
"not implemented");
394 HRESULT PathCchCanonicalizeExW(PWSTR pszPathOut,
size_t cchPathOut, PCWSTR pszPathIn,
395 unsigned long dwFlags)
397 WLog_ERR(TAG,
"not implemented");
405 HRESULT PathAllocCanonicalizeA(PCSTR pszPathIn,
unsigned long dwFlags, PSTR* ppszPathOut)
407 WLog_ERR(TAG,
"not implemented");
411 HRESULT PathAllocCanonicalizeW(PCWSTR pszPathIn,
unsigned long dwFlags, PWSTR* ppszPathOut)
413 WLog_ERR(TAG,
"not implemented");
421 HRESULT PathCchCombineA(PSTR pszPathOut,
size_t cchPathOut, PCSTR pszPathIn, PCSTR pszMore)
423 WLog_ERR(TAG,
"not implemented");
427 HRESULT PathCchCombineW(PWSTR pszPathOut,
size_t cchPathOut, PCWSTR pszPathIn, PCWSTR pszMore)
429 WLog_ERR(TAG,
"not implemented");
437 HRESULT PathCchCombineExA(PSTR pszPathOut,
size_t cchPathOut, PCSTR pszPathIn, PCSTR pszMore,
438 unsigned long dwFlags)
440 WLog_ERR(TAG,
"not implemented");
444 HRESULT PathCchCombineExW(PWSTR pszPathOut,
size_t cchPathOut, PCWSTR pszPathIn, PCWSTR pszMore,
445 unsigned long dwFlags)
447 WLog_ERR(TAG,
"not implemented");
457 #define DEFINE_UNICODE FALSE
458 #define CUR_PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
459 #define CUR_PATH_SEPARATOR_STR PATH_BACKSLASH_STR
460 #define PATH_ALLOC_COMBINE PathAllocCombineA
461 #include "include/PathAllocCombine.h"
462 #undef DEFINE_UNICODE
463 #undef CUR_PATH_SEPARATOR_CHR
464 #undef CUR_PATH_SEPARATOR_STR
465 #undef PATH_ALLOC_COMBINE
467 #define DEFINE_UNICODE TRUE
468 #define CUR_PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
469 #define CUR_PATH_SEPARATOR_STR PATH_BACKSLASH_STR_W
470 #define PATH_ALLOC_COMBINE PathAllocCombineW
471 #include "include/PathAllocCombine.h"
472 #undef DEFINE_UNICODE
473 #undef CUR_PATH_SEPARATOR_CHR
474 #undef CUR_PATH_SEPARATOR_STR
475 #undef PATH_ALLOC_COMBINE
479 #define DEFINE_UNICODE FALSE
480 #define CUR_PATH_SEPARATOR_CHR PATH_SLASH_CHR
481 #define CUR_PATH_SEPARATOR_STR PATH_SLASH_STR
482 #define PATH_ALLOC_COMBINE UnixPathAllocCombineA
483 #include "include/PathAllocCombine.h"
484 #undef DEFINE_UNICODE
485 #undef CUR_PATH_SEPARATOR_CHR
486 #undef CUR_PATH_SEPARATOR_STR
487 #undef PATH_ALLOC_COMBINE
489 #define DEFINE_UNICODE TRUE
490 #define CUR_PATH_SEPARATOR_CHR PATH_SLASH_CHR
491 #define CUR_PATH_SEPARATOR_STR PATH_SLASH_STR_W
492 #define PATH_ALLOC_COMBINE UnixPathAllocCombineW
493 #include "include/PathAllocCombine.h"
494 #undef DEFINE_UNICODE
495 #undef CUR_PATH_SEPARATOR_CHR
496 #undef CUR_PATH_SEPARATOR_STR
497 #undef PATH_ALLOC_COMBINE
501 #define DEFINE_UNICODE FALSE
502 #define CUR_PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
503 #define CUR_PATH_SEPARATOR_STR PATH_SEPARATOR_STR
504 #define PATH_ALLOC_COMBINE NativePathAllocCombineA
505 #include "include/PathAllocCombine.h"
506 #undef DEFINE_UNICODE
507 #undef CUR_PATH_SEPARATOR_CHR
508 #undef CUR_PATH_SEPARATOR_STR
509 #undef PATH_ALLOC_COMBINE
511 #define DEFINE_UNICODE TRUE
512 #define CUR_PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
513 #define CUR_PATH_SEPARATOR_STR PATH_SEPARATOR_STR_W
514 #define PATH_ALLOC_COMBINE NativePathAllocCombineW
515 #include "include/PathAllocCombine.h"
516 #undef DEFINE_UNICODE
517 #undef CUR_PATH_SEPARATOR_CHR
518 #undef CUR_PATH_SEPARATOR_STR
519 #undef PATH_ALLOC_COMBINE
525 HRESULT PathCchFindExtensionA(PCSTR pszPath,
size_t cchPath, PCSTR* ppszExt)
527 const char* p = (
const char*)pszPath;
529 if (!pszPath || !cchPath || !ppszExt)
534 while (*p && --cchPath)
558 if ((*p ==
'\\') || (*p ==
'/') || (*p ==
':'))
567 HRESULT PathCchFindExtensionW(PCWSTR pszPath,
size_t cchPath, PCWSTR* ppszExt)
569 WLog_ERR(TAG,
"not implemented");
577 HRESULT PathCchRenameExtensionA(PSTR pszPath,
size_t cchPath, PCSTR pszExt)
579 WLog_ERR(TAG,
"not implemented");
583 HRESULT PathCchRenameExtensionW(PWSTR pszPath,
size_t cchPath, PCWSTR pszExt)
585 WLog_ERR(TAG,
"not implemented");
593 HRESULT PathCchRemoveExtensionA(PSTR pszPath,
size_t cchPath)
595 WLog_ERR(TAG,
"not implemented");
599 HRESULT PathCchRemoveExtensionW(PWSTR pszPath,
size_t cchPath)
601 WLog_ERR(TAG,
"not implemented");
609 BOOL PathCchIsRootA(PCSTR pszPath)
611 WLog_ERR(TAG,
"not implemented");
615 BOOL PathCchIsRootW(PCWSTR pszPath)
617 WLog_ERR(TAG,
"not implemented");
625 BOOL PathIsUNCExA(PCSTR pszPath, PCSTR* ppszServer)
630 if ((pszPath[0] ==
'\\') && (pszPath[1] ==
'\\'))
632 *ppszServer = &pszPath[2];
639 BOOL PathIsUNCExW(PCWSTR pszPath, PCWSTR* ppszServer)
644 if ((pszPath[0] ==
'\\') && (pszPath[1] ==
'\\'))
646 *ppszServer = &pszPath[2];
657 HRESULT PathCchSkipRootA(PCSTR pszPath, PCSTR* ppszRootEnd)
659 WLog_ERR(TAG,
"not implemented");
663 HRESULT PathCchSkipRootW(PCWSTR pszPath, PCWSTR* ppszRootEnd)
665 WLog_ERR(TAG,
"not implemented");
673 HRESULT PathCchStripToRootA(PSTR pszPath,
size_t cchPath)
675 WLog_ERR(TAG,
"not implemented");
679 HRESULT PathCchStripToRootW(PWSTR pszPath,
size_t cchPath)
681 WLog_ERR(TAG,
"not implemented");
689 HRESULT PathCchStripPrefixA(PSTR pszPath,
size_t cchPath)
696 if (cchPath < 4 || cchPath > PATHCCH_MAX_CCH)
699 hasPrefix = ((pszPath[0] ==
'\\') && (pszPath[1] ==
'\\') && (pszPath[2] ==
'?') &&
700 (pszPath[3] ==
'\\'))
709 if (IsCharAlpha(pszPath[4]) && (pszPath[5] ==
':'))
711 memmove_s(pszPath, cchPath, &pszPath[4], cchPath - 4);
716 pszPath[cchPath - 4] = 0;
724 HRESULT PathCchStripPrefixW(PWSTR pszPath,
size_t cchPath)
731 if (cchPath < 4 || cchPath > PATHCCH_MAX_CCH)
734 hasPrefix = ((pszPath[0] ==
'\\') && (pszPath[1] ==
'\\') && (pszPath[2] ==
'?') &&
735 (pszPath[3] ==
'\\'))
744 const size_t rc = (_wcslen(&pszPath[4]) + 1);
746 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
748 if (IsCharAlphaW(pszPath[4]) && (pszPath[5] == L
':'))
750 wmemmove_s(pszPath, cchPath, &pszPath[4], cchPath - 4);
755 pszPath[cchPath - 4] = 0;
767 HRESULT PathCchRemoveFileSpecA(PSTR pszPath,
size_t cchPath)
769 WLog_ERR(TAG,
"not implemented");
773 HRESULT PathCchRemoveFileSpecW(PWSTR pszPath,
size_t cchPath)
775 WLog_ERR(TAG,
"not implemented");
787 HRESULT PathCchConvertStyleA(PSTR pszPath,
size_t cchPath,
unsigned long dwFlags)
789 if (dwFlags == PATH_STYLE_WINDOWS)
791 for (
size_t index = 0; index < cchPath; index++)
793 if (pszPath[index] == PATH_SLASH_CHR)
794 pszPath[index] = PATH_BACKSLASH_CHR;
797 else if (dwFlags == PATH_STYLE_UNIX)
799 for (
size_t index = 0; index < cchPath; index++)
801 if (pszPath[index] == PATH_BACKSLASH_CHR)
802 pszPath[index] = PATH_SLASH_CHR;
805 else if (dwFlags == PATH_STYLE_NATIVE)
807 #if (PATH_SEPARATOR_CHR == PATH_BACKSLASH_CHR)
810 for (
size_t index = 0; index < cchPath; index++)
812 if (pszPath[index] == PATH_SLASH_CHR)
813 pszPath[index] = PATH_BACKSLASH_CHR;
815 #elif (PATH_SEPARATOR_CHR == PATH_SLASH_CHR)
818 for (
size_t index = 0; index < cchPath; index++)
820 if (pszPath[index] == PATH_BACKSLASH_CHR)
821 pszPath[index] = PATH_SLASH_CHR;
837 HRESULT PathCchConvertStyleW(PWSTR pszPath,
size_t cchPath,
unsigned long dwFlags)
839 if (dwFlags == PATH_STYLE_WINDOWS)
841 for (
size_t index = 0; index < cchPath; index++)
843 if (pszPath[index] == PATH_SLASH_CHR)
844 pszPath[index] = PATH_BACKSLASH_CHR;
847 else if (dwFlags == PATH_STYLE_UNIX)
849 for (
size_t index = 0; index < cchPath; index++)
851 if (pszPath[index] == PATH_BACKSLASH_CHR)
852 pszPath[index] = PATH_SLASH_CHR;
855 else if (dwFlags == PATH_STYLE_NATIVE)
857 #if (PATH_SEPARATOR_CHR == PATH_BACKSLASH_CHR)
861 for (
size_t index = 0; index < cchPath; index++)
863 if (pszPath[index] == PATH_SLASH_CHR)
864 pszPath[index] = PATH_BACKSLASH_CHR;
867 #elif (PATH_SEPARATOR_CHR == PATH_SLASH_CHR)
871 for (
size_t index = 0; index < cchPath; index++)
873 if (pszPath[index] == PATH_BACKSLASH_CHR)
874 pszPath[index] = PATH_SLASH_CHR;
897 char PathGetSeparatorA(
unsigned long dwFlags)
899 char separator = PATH_SEPARATOR_CHR;
902 dwFlags = PATH_STYLE_NATIVE;
904 if (dwFlags == PATH_STYLE_WINDOWS)
905 separator = PATH_SEPARATOR_CHR;
906 else if (dwFlags == PATH_STYLE_UNIX)
907 separator = PATH_SEPARATOR_CHR;
908 else if (dwFlags == PATH_STYLE_NATIVE)
909 separator = PATH_SEPARATOR_CHR;
914 WCHAR PathGetSeparatorW(
unsigned long dwFlags)
922 cnv.c[0] = PATH_SEPARATOR_CHR;
926 dwFlags = PATH_STYLE_NATIVE;
928 if (dwFlags == PATH_STYLE_WINDOWS)
929 cnv.c[0] = PATH_SEPARATOR_CHR;
930 else if (dwFlags == PATH_STYLE_UNIX)
931 cnv.c[0] = PATH_SEPARATOR_CHR;
932 else if (dwFlags == PATH_STYLE_NATIVE)
933 cnv.c[0] = PATH_SEPARATOR_CHR;
941 static const CHAR SharedLibraryExtensionDllA[] =
"dll";
942 static const CHAR SharedLibraryExtensionSoA[] =
"so";
943 static const CHAR SharedLibraryExtensionDylibA[] =
"dylib";
945 static const CHAR SharedLibraryExtensionDotDllA[] =
".dll";
946 static const CHAR SharedLibraryExtensionDotSoA[] =
".so";
947 static const CHAR SharedLibraryExtensionDotDylibA[] =
".dylib";
948 PCSTR PathGetSharedLibraryExtensionA(
unsigned long dwFlags)
950 if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT)
952 if (dwFlags & PATH_SHARED_LIB_EXT_WITH_DOT)
954 if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_DLL)
955 return SharedLibraryExtensionDotDllA;
957 if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_SO)
958 return SharedLibraryExtensionDotSoA;
960 if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_DYLIB)
961 return SharedLibraryExtensionDotDylibA;
965 if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_DLL)
966 return SharedLibraryExtensionDllA;
968 if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_SO)
969 return SharedLibraryExtensionSoA;
971 if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_DYLIB)
972 return SharedLibraryExtensionDylibA;
976 if (dwFlags & PATH_SHARED_LIB_EXT_WITH_DOT)
979 return SharedLibraryExtensionDotDllA;
980 #elif defined(__APPLE__)
981 if (dwFlags & PATH_SHARED_LIB_EXT_APPLE_SO)
982 return SharedLibraryExtensionDotSoA;
984 return SharedLibraryExtensionDotDylibA;
986 return SharedLibraryExtensionDotSoA;
992 return SharedLibraryExtensionDllA;
993 #elif defined(__APPLE__)
994 if (dwFlags & PATH_SHARED_LIB_EXT_APPLE_SO)
995 return SharedLibraryExtensionSoA;
997 return SharedLibraryExtensionDylibA;
999 return SharedLibraryExtensionSoA;
1006 PCWSTR PathGetSharedLibraryExtensionW(
unsigned long dwFlags)
1008 static WCHAR buffer[6][16] = { 0 };
1009 const WCHAR* SharedLibraryExtensionDotDllW = InitializeConstWCharFromUtf8(
1010 SharedLibraryExtensionDotDllA, buffer[0], ARRAYSIZE(buffer[0]));
1011 const WCHAR* SharedLibraryExtensionDotSoW =
1012 InitializeConstWCharFromUtf8(SharedLibraryExtensionDotSoA, buffer[1], ARRAYSIZE(buffer[1]));
1013 const WCHAR* SharedLibraryExtensionDotDylibW = InitializeConstWCharFromUtf8(
1014 SharedLibraryExtensionDotDylibA, buffer[2], ARRAYSIZE(buffer[2]));
1015 const WCHAR* SharedLibraryExtensionDllW =
1016 InitializeConstWCharFromUtf8(SharedLibraryExtensionDllA, buffer[3], ARRAYSIZE(buffer[3]));
1017 const WCHAR* SharedLibraryExtensionSoW =
1018 InitializeConstWCharFromUtf8(SharedLibraryExtensionSoA, buffer[4], ARRAYSIZE(buffer[4]));
1019 const WCHAR* SharedLibraryExtensionDylibW =
1020 InitializeConstWCharFromUtf8(SharedLibraryExtensionDylibA, buffer[5], ARRAYSIZE(buffer[5]));
1022 if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT)
1024 if (dwFlags & PATH_SHARED_LIB_EXT_WITH_DOT)
1026 if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_DLL)
1027 return SharedLibraryExtensionDotDllW;
1029 if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_SO)
1030 return SharedLibraryExtensionDotSoW;
1032 if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_DYLIB)
1033 return SharedLibraryExtensionDotDylibW;
1037 if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_DLL)
1038 return SharedLibraryExtensionDllW;
1040 if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_SO)
1041 return SharedLibraryExtensionSoW;
1043 if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_DYLIB)
1044 return SharedLibraryExtensionDylibW;
1048 if (dwFlags & PATH_SHARED_LIB_EXT_WITH_DOT)
1051 return SharedLibraryExtensionDotDllW;
1052 #elif defined(__APPLE__)
1053 if (dwFlags & PATH_SHARED_LIB_EXT_APPLE_SO)
1054 return SharedLibraryExtensionDotSoW;
1056 return SharedLibraryExtensionDotDylibW;
1058 return SharedLibraryExtensionDotSoW;
1064 return SharedLibraryExtensionDllW;
1065 #elif defined(__APPLE__)
1066 if (dwFlags & PATH_SHARED_LIB_EXT_APPLE_SO)
1067 return SharedLibraryExtensionSoW;
1069 return SharedLibraryExtensionDylibW;
1071 return SharedLibraryExtensionSoW;
1078 const char* GetKnownPathIdString(
int id)
1082 case KNOWN_PATH_HOME:
1083 return "KNOWN_PATH_HOME";
1084 case KNOWN_PATH_TEMP:
1085 return "KNOWN_PATH_TEMP";
1086 case KNOWN_PATH_XDG_DATA_HOME:
1087 return "KNOWN_PATH_XDG_DATA_HOME";
1088 case KNOWN_PATH_XDG_CONFIG_HOME:
1089 return "KNOWN_PATH_XDG_CONFIG_HOME";
1090 case KNOWN_PATH_XDG_CACHE_HOME:
1091 return "KNOWN_PATH_XDG_CACHE_HOME";
1092 case KNOWN_PATH_XDG_RUNTIME_DIR:
1093 return "KNOWN_PATH_XDG_RUNTIME_DIR";
1094 case KNOWN_PATH_SYSTEM_CONFIG_HOME:
1095 return "KNOWN_PATH_SYSTEM_CONFIG_HOME";
1097 return "KNOWN_PATH_UNKNOWN_ID";
1101 static WCHAR* concat(
const WCHAR* path,
size_t pathlen,
const WCHAR* name,
size_t namelen)
1103 WCHAR* str = calloc(pathlen + namelen + 1,
sizeof(WCHAR));
1107 _wcsncat(str, path, pathlen);
1108 _wcsncat(str, name, namelen);
1112 BOOL winpr_RemoveDirectory_RecursiveA(LPCSTR lpPathName)
1114 WCHAR* name = ConvertUtf8ToWCharAlloc(lpPathName, NULL);
1117 const BOOL rc = winpr_RemoveDirectory_RecursiveW(name);
1122 BOOL winpr_RemoveDirectory_RecursiveW(LPCWSTR lpPathName)
1129 const size_t pathnamelen = _wcslen(lpPathName);
1130 const size_t path_slash_len = pathnamelen + 3;
1131 WCHAR* path_slash = calloc(pathnamelen + 4,
sizeof(WCHAR));
1134 _wcsncat(path_slash, lpPathName, pathnamelen);
1136 WCHAR starbuffer[8] = { 0 };
1137 const WCHAR* star = InitializeConstWCharFromUtf8(
"*", starbuffer, ARRAYSIZE(starbuffer));
1138 const HRESULT hr = NativePathCchAppendW(path_slash, path_slash_len, star);
1139 HANDLE dir = INVALID_HANDLE_VALUE;
1144 dir = FindFirstFileW(path_slash, &findFileData);
1146 if (dir == INVALID_HANDLE_VALUE)
1150 path_slash[path_slash_len - 1] =
'\0';
1153 const size_t len = _wcsnlen(findFileData.cFileName, ARRAYSIZE(findFileData.cFileName));
1155 if ((len == 1 && findFileData.cFileName[0] ==
'.') ||
1156 (len == 2 && findFileData.cFileName[0] ==
'.' && findFileData.cFileName[1] ==
'.'))
1161 WCHAR* fullpath = concat(path_slash, path_slash_len, findFileData.cFileName, len);
1165 if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1166 ret = winpr_RemoveDirectory_RecursiveW(fullpath);
1168 ret = DeleteFileW(fullpath);
1174 }
while (ret && FindNextFileW(dir, &findFileData) != 0);
1178 if (!RemoveDirectoryW(lpPathName))
1188 char* winpr_GetConfigFilePath(BOOL system,
const char* filename)
1190 eKnownPathTypes
id = system ? KNOWN_PATH_SYSTEM_CONFIG_HOME : KNOWN_PATH_XDG_CONFIG_HOME;
1192 #if defined(WINPR_USE_VENDOR_PRODUCT_CONFIG_DIR)
1193 char* vendor = GetKnownSubPath(
id, WINPR_VENDOR_STRING);
1196 #if defined(WITH_RESOURCE_VERSIONING)
1197 const char* prod = WINPR_PRODUCT_STRING STR(WINPR_VERSION_MAJOR);
1199 const char* prod = WINPR_PRODUCT_STRING;
1201 char* base = GetCombinedPath(vendor, prod);
1204 char* base = GetKnownSubPath(
id,
"winpr");
1212 char* path = GetCombinedPath(base, filename);