/src/FreeRDP/winpr/libwinpr/path/include/PathCchAddSeparatorEx.h
Line | Count | Source |
1 | | |
2 | | #include <winpr/wtypes.h> |
3 | | |
4 | | /* |
5 | | #define DEFINE_UNICODE FALSE |
6 | | #define CUR_PATH_SEPARATOR_CHR '\\' |
7 | | #define PATH_CCH_ADD_SEPARATOR_EX PathCchAddBackslashExA |
8 | | */ |
9 | | |
10 | | #if DEFINE_UNICODE |
11 | | |
12 | | HRESULT PATH_CCH_ADD_SEPARATOR_EX(PWSTR pszPath, size_t cchPath, WINPR_ATTR_UNUSED PWSTR* ppszEnd, |
13 | | WINPR_ATTR_UNUSED size_t* pcchRemaining) |
14 | 0 | { |
15 | 0 | WINPR_ASSERT(pszPath || (cchPath == 0)); |
16 | 0 | if (!pszPath) |
17 | 0 | return S_OK; |
18 | | |
19 | 0 | const size_t pszPathLength = _wcsnlen(pszPath, cchPath); |
20 | 0 | if (pszPathLength < 1) |
21 | 0 | return S_OK; |
22 | | |
23 | 0 | if (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) |
24 | 0 | return S_FALSE; |
25 | | |
26 | 0 | if (cchPath > (pszPathLength + 1)) |
27 | 0 | { |
28 | 0 | pszPath[pszPathLength] = CUR_PATH_SEPARATOR_CHR; |
29 | 0 | pszPath[pszPathLength + 1] = '\0'; |
30 | |
|
31 | 0 | return S_OK; |
32 | 0 | } |
33 | | |
34 | 0 | return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); |
35 | 0 | } Unexecuted instantiation: PathCchAddBackslashExW Unexecuted instantiation: PathCchAddSlashExW Unexecuted instantiation: PathCchAddSeparatorExW |
36 | | |
37 | | #else |
38 | | |
39 | | HRESULT PATH_CCH_ADD_SEPARATOR_EX(WINPR_ATTR_UNUSED PSTR pszPath, WINPR_ATTR_UNUSED size_t cchPath, |
40 | | WINPR_ATTR_UNUSED PSTR* ppszEnd, |
41 | | WINPR_ATTR_UNUSED size_t* pcchRemaining) |
42 | 0 | { |
43 | 0 | WINPR_ASSERT(pszPath || (cchPath == 0)); |
44 | 0 | if (!pszPath) |
45 | 0 | return S_OK; |
46 | | |
47 | 0 | const size_t pszPathLength = strnlen(pszPath, cchPath); |
48 | 0 | if (pszPathLength < 1) |
49 | 0 | return S_OK; |
50 | | |
51 | 0 | if (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) |
52 | 0 | return S_FALSE; |
53 | | |
54 | 0 | if (cchPath > (pszPathLength + 1)) |
55 | 0 | { |
56 | 0 | pszPath[pszPathLength] = CUR_PATH_SEPARATOR_CHR; |
57 | 0 | pszPath[pszPathLength + 1] = '\0'; |
58 | |
|
59 | 0 | return S_OK; |
60 | 0 | } |
61 | | |
62 | 0 | return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); |
63 | 0 | } Unexecuted instantiation: PathCchAddBackslashExA Unexecuted instantiation: PathCchAddSlashExA Unexecuted instantiation: PathCchAddSeparatorExA |
64 | | |
65 | | #endif |
66 | | |
67 | | /* |
68 | | #undef DEFINE_UNICODE |
69 | | #undef CUR_PATH_SEPARATOR_CHR |
70 | | #undef PATH_CCH_ADD_SEPARATOR_EX |
71 | | */ |