24 #include <winpr/wtypes.h>
25 #include <winpr/error.h>
26 #include <winpr/wlog.h>
30 HRESULT PATH_ALLOC_COMBINE(PCWSTR pszPathIn, PCWSTR pszMore,
unsigned long dwFlags,
33 WLog_WARN(TAG,
"has known bugs and needs fixing.");
38 if (!pszPathIn && !pszMore)
47 const size_t pszPathInLength = _wcslen(pszPathIn);
48 const size_t pszMoreLength = _wcslen(pszMore);
51 if (pszPathInLength < 3)
54 const BOOL backslashIn =
55 (pszPathIn[pszPathInLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
56 const BOOL backslashMore = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
60 if ((pszPathIn[1] ==
':') && (pszPathIn[2] == CUR_PATH_SEPARATOR_CHR))
62 const WCHAR colon[] = {
':',
'\0' };
63 const size_t pszPathOutLength =
sizeof(WCHAR) + pszMoreLength;
64 const size_t sizeOfBuffer = (pszPathOutLength + 1) *
sizeof(WCHAR);
65 PWSTR pszPathOut = (PWSTR)calloc(sizeOfBuffer,
sizeof(WCHAR));
70 _wcsncat(pszPathOut, &pszPathIn[0], 1);
71 _wcsncat(pszPathOut, colon, ARRAYSIZE(colon));
72 _wcsncat(pszPathOut, pszMore, pszMoreLength);
73 *ppszPathOut = pszPathOut;
79 const WCHAR sep[] = CUR_PATH_SEPARATOR_STR;
80 const size_t pszPathOutLength = pszPathInLength + pszMoreLength;
81 const size_t sizeOfBuffer = (pszPathOutLength + 1) * 2;
82 PWSTR pszPathOut = (PWSTR)calloc(sizeOfBuffer, 2);
87 _wcsncat(pszPathOut, pszPathIn, pszPathInLength);
89 _wcsncat(pszPathOut, sep, ARRAYSIZE(sep));
90 _wcsncat(pszPathOut, pszMore, pszMoreLength);
92 *ppszPathOut = pszPathOut;
101 HRESULT PATH_ALLOC_COMBINE(PCSTR pszPathIn, PCSTR pszMore,
unsigned long dwFlags, PSTR* ppszPathOut)
103 WLog_WARN(TAG,
"has known bugs and needs fixing.");
108 if (!pszPathIn && !pszMore)
117 const size_t pszPathInLength = strlen(pszPathIn);
118 const size_t pszMoreLength = strlen(pszMore);
121 if (pszPathInLength < 3)
124 const BOOL backslashIn =
125 (pszPathIn[pszPathInLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
126 const BOOL backslashMore = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
130 if ((pszPathIn[1] ==
':') && (pszPathIn[2] == CUR_PATH_SEPARATOR_CHR))
132 const size_t pszPathOutLength = 2 + pszMoreLength;
133 const size_t sizeOfBuffer = (pszPathOutLength + 1) * 2;
134 PSTR pszPathOut = calloc(sizeOfBuffer, 2);
137 return E_OUTOFMEMORY;
139 sprintf_s(pszPathOut, sizeOfBuffer,
"%c:%s", pszPathIn[0], pszMore);
140 *ppszPathOut = pszPathOut;
146 const size_t pszPathOutLength = pszPathInLength + pszMoreLength;
147 const size_t sizeOfBuffer = (pszPathOutLength + 1) * 2;
148 PSTR pszPathOut = calloc(sizeOfBuffer, 2);
151 return E_OUTOFMEMORY;
154 sprintf_s(pszPathOut, sizeOfBuffer,
"%s%s", pszPathIn, pszMore);
156 sprintf_s(pszPathOut, sizeOfBuffer,
"%s" CUR_PATH_SEPARATOR_STR
"%s", pszPathIn,
159 *ppszPathOut = pszPathOut;