/src/FreeRDP/winpr/libwinpr/path/include/PathCchAppend.c
Line | Count | Source (jump to first uncovered line) |
1 | | |
2 | | /* |
3 | | #define DEFINE_UNICODE FALSE |
4 | | #define CUR_PATH_SEPARATOR_CHR '\\' |
5 | | #define CUR_PATH_SEPARATOR_STR "\\" |
6 | | #define PATH_CCH_APPEND PathCchAppendA |
7 | | */ |
8 | | |
9 | | #if DEFINE_UNICODE |
10 | | |
11 | | HRESULT PATH_CCH_APPEND(PWSTR pszPath, size_t cchPath, PCWSTR pszMore) |
12 | 0 | { |
13 | 0 | BOOL pathBackslash; |
14 | 0 | BOOL moreBackslash; |
15 | 0 | size_t pszMoreLength; |
16 | 0 | size_t pszPathLength; |
17 | |
|
18 | 0 | if (!pszPath) |
19 | 0 | return E_INVALIDARG; |
20 | | |
21 | 0 | if (!pszMore) |
22 | 0 | return E_INVALIDARG; |
23 | | |
24 | 0 | if (cchPath == 0 || cchPath > PATHCCH_MAX_CCH) |
25 | 0 | return E_INVALIDARG; |
26 | | |
27 | 0 | pszMoreLength = _wcslen(pszMore); |
28 | 0 | pszPathLength = _wcslen(pszPath); |
29 | |
|
30 | 0 | pathBackslash = (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE; |
31 | 0 | moreBackslash = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE; |
32 | |
|
33 | 0 | if (pathBackslash && moreBackslash) |
34 | 0 | { |
35 | 0 | if ((pszPathLength + pszMoreLength - 1) < cchPath) |
36 | 0 | { |
37 | 0 | WCHAR* ptr = &pszPath[pszPathLength]; |
38 | 0 | *ptr = '\0'; |
39 | 0 | _wcsncat(ptr, &pszMore[1], _wcslen(&pszMore[1])); |
40 | 0 | return S_OK; |
41 | 0 | } |
42 | 0 | } |
43 | 0 | else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash)) |
44 | 0 | { |
45 | 0 | if ((pszPathLength + pszMoreLength) < cchPath) |
46 | 0 | { |
47 | 0 | WCHAR* ptr = &pszPath[pszPathLength]; |
48 | 0 | *ptr = '\0'; |
49 | 0 | _wcsncat(ptr, pszMore, _wcslen(pszMore)); |
50 | 0 | return S_OK; |
51 | 0 | } |
52 | 0 | } |
53 | 0 | else if (!pathBackslash && !moreBackslash) |
54 | 0 | { |
55 | 0 | if ((pszPathLength + pszMoreLength + 1) < cchPath) |
56 | 0 | { |
57 | 0 | const WCHAR sep[] = CUR_PATH_SEPARATOR_STR; |
58 | 0 | WCHAR* ptr = &pszPath[pszPathLength]; |
59 | 0 | *ptr = '\0'; |
60 | 0 | _wcsncat(ptr, sep, _wcslen(sep)); |
61 | 0 | _wcsncat(ptr, pszMore, _wcslen(pszMore)); |
62 | 0 | return S_OK; |
63 | 0 | } |
64 | 0 | } |
65 | | |
66 | 0 | return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE); |
67 | 0 | } Unexecuted instantiation: PathCchAppendW Unexecuted instantiation: UnixPathCchAppendW Unexecuted instantiation: NativePathCchAppendW |
68 | | |
69 | | #else |
70 | | |
71 | | HRESULT PATH_CCH_APPEND(PSTR pszPath, size_t cchPath, PCSTR pszMore) |
72 | 44.9k | { |
73 | 44.9k | BOOL pathBackslash = FALSE; |
74 | 44.9k | BOOL moreBackslash = FALSE; |
75 | 44.9k | size_t pszMoreLength; |
76 | 44.9k | size_t pszPathLength; |
77 | | |
78 | 44.9k | if (!pszPath) |
79 | 0 | return E_INVALIDARG; |
80 | | |
81 | 44.9k | if (!pszMore) |
82 | 0 | return E_INVALIDARG; |
83 | | |
84 | 44.9k | if (cchPath == 0 || cchPath > PATHCCH_MAX_CCH) |
85 | 0 | return E_INVALIDARG; |
86 | | |
87 | 44.9k | pszPathLength = strlen(pszPath); |
88 | 44.9k | if (pszPathLength > 0) |
89 | 44.9k | pathBackslash = (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE; |
90 | | |
91 | 44.9k | pszMoreLength = strlen(pszMore); |
92 | 44.9k | if (pszMoreLength > 0) |
93 | 44.9k | moreBackslash = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE; |
94 | | |
95 | 44.9k | if (pathBackslash && moreBackslash) |
96 | 0 | { |
97 | 0 | if ((pszPathLength + pszMoreLength - 1) < cchPath) |
98 | 0 | { |
99 | 0 | sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", &pszMore[1]); |
100 | 0 | return S_OK; |
101 | 0 | } |
102 | 0 | } |
103 | 44.9k | else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash)) |
104 | 0 | { |
105 | 0 | if ((pszPathLength + pszMoreLength) < cchPath) |
106 | 0 | { |
107 | 0 | sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", pszMore); |
108 | 0 | return S_OK; |
109 | 0 | } |
110 | 0 | } |
111 | 44.9k | else if (!pathBackslash && !moreBackslash) |
112 | 44.9k | { |
113 | 44.9k | if ((pszPathLength + pszMoreLength + 1) < cchPath) |
114 | 44.9k | { |
115 | 44.9k | sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, CUR_PATH_SEPARATOR_STR "%s", |
116 | 44.9k | pszMore); |
117 | 44.9k | return S_OK; |
118 | 44.9k | } |
119 | 44.9k | } |
120 | | |
121 | 0 | return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE); |
122 | 44.9k | } Unexecuted instantiation: PathCchAppendA Unexecuted instantiation: UnixPathCchAppendA Line | Count | Source | 72 | 44.9k | { | 73 | 44.9k | BOOL pathBackslash = FALSE; | 74 | 44.9k | BOOL moreBackslash = FALSE; | 75 | 44.9k | size_t pszMoreLength; | 76 | 44.9k | size_t pszPathLength; | 77 | | | 78 | 44.9k | if (!pszPath) | 79 | 0 | return E_INVALIDARG; | 80 | | | 81 | 44.9k | if (!pszMore) | 82 | 0 | return E_INVALIDARG; | 83 | | | 84 | 44.9k | if (cchPath == 0 || cchPath > PATHCCH_MAX_CCH) | 85 | 0 | return E_INVALIDARG; | 86 | | | 87 | 44.9k | pszPathLength = strlen(pszPath); | 88 | 44.9k | if (pszPathLength > 0) | 89 | 44.9k | pathBackslash = (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE; | 90 | | | 91 | 44.9k | pszMoreLength = strlen(pszMore); | 92 | 44.9k | if (pszMoreLength > 0) | 93 | 44.9k | moreBackslash = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE; | 94 | | | 95 | 44.9k | if (pathBackslash && moreBackslash) | 96 | 0 | { | 97 | 0 | if ((pszPathLength + pszMoreLength - 1) < cchPath) | 98 | 0 | { | 99 | 0 | sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", &pszMore[1]); | 100 | 0 | return S_OK; | 101 | 0 | } | 102 | 0 | } | 103 | 44.9k | else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash)) | 104 | 0 | { | 105 | 0 | if ((pszPathLength + pszMoreLength) < cchPath) | 106 | 0 | { | 107 | 0 | sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", pszMore); | 108 | 0 | return S_OK; | 109 | 0 | } | 110 | 0 | } | 111 | 44.9k | else if (!pathBackslash && !moreBackslash) | 112 | 44.9k | { | 113 | 44.9k | if ((pszPathLength + pszMoreLength + 1) < cchPath) | 114 | 44.9k | { | 115 | 44.9k | sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, CUR_PATH_SEPARATOR_STR "%s", | 116 | 44.9k | pszMore); | 117 | 44.9k | return S_OK; | 118 | 44.9k | } | 119 | 44.9k | } | 120 | | | 121 | 0 | return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE); | 122 | 44.9k | } |
|
123 | | |
124 | | #endif |
125 | | |
126 | | /* |
127 | | #undef DEFINE_UNICODE |
128 | | #undef CUR_PATH_SEPARATOR_CHR |
129 | | #undef CUR_PATH_SEPARATOR_STR |
130 | | #undef PATH_CCH_APPEND |
131 | | */ |