24#include <winpr/wtypes.h>
25#include <winpr/string.h>
26#include <winpr/error.h>
27#include <winpr/wlog.h>
31HRESULT PATH_ALLOC_COMBINE(PCWSTR pszPathIn, PCWSTR pszMore,
32 WINPR_ATTR_UNUSED
unsigned long dwFlags, PWSTR* ppszPathOut)
34 WLog_WARN(
"TODO",
"has known bugs and needs fixing.");
39 if (!pszPathIn && !pszMore)
48 const size_t pszPathInLength = _wcslen(pszPathIn);
49 const size_t pszMoreLength = _wcslen(pszMore);
52 if (pszPathInLength < 3)
55 const BOOL backslashIn =
56 (pszPathIn[pszPathInLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
57 const BOOL backslashMore = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
61 if ((pszPathIn[1] ==
':') && (pszPathIn[2] == CUR_PATH_SEPARATOR_CHR))
63 const WCHAR colon[] = {
':',
'\0' };
64 const size_t pszPathOutLength =
sizeof(WCHAR) + pszMoreLength;
65 const size_t sizeOfBuffer = (pszPathOutLength + 1) *
sizeof(WCHAR);
66 PWSTR pszPathOut = (PWSTR)calloc(sizeOfBuffer,
sizeof(WCHAR));
71 _wcsncat(pszPathOut, &pszPathIn[0], 1);
72 _wcsncat(pszPathOut, colon, ARRAYSIZE(colon));
73 _wcsncat(pszPathOut, pszMore, pszMoreLength);
74 *ppszPathOut = pszPathOut;
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, CUR_PATH_SEPARATOR_STR, ARRAYSIZE(CUR_PATH_SEPARATOR_STR));
90 _wcsncat(pszPathOut, pszMore, pszMoreLength);
92 *ppszPathOut = pszPathOut;
101HRESULT PATH_ALLOC_COMBINE(PCSTR pszPathIn, PCSTR pszMore, WINPR_ATTR_UNUSED
unsigned long dwFlags,
104 WLog_WARN(
"TODO",
"has known bugs and needs fixing.");
109 if (!pszPathIn && !pszMore)
118 const size_t pszPathInLength = strlen(pszPathIn);
119 const size_t pszMoreLength = strlen(pszMore);
122 if (pszPathInLength < 3)
125 const BOOL backslashIn =
126 (pszPathIn[pszPathInLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
127 const BOOL backslashMore = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
131 if ((pszPathIn[1] ==
':') && (pszPathIn[2] == CUR_PATH_SEPARATOR_CHR))
133 const size_t pszPathOutLength = 2 + pszMoreLength;
134 const size_t sizeOfBuffer = (pszPathOutLength + 1) * 2;
135 PSTR pszPathOut = calloc(sizeOfBuffer, 2);
138 return E_OUTOFMEMORY;
140 (void)sprintf_s(pszPathOut, sizeOfBuffer,
"%c:%s", pszPathIn[0], pszMore);
141 *ppszPathOut = pszPathOut;
147 const size_t pszPathOutLength = pszPathInLength + pszMoreLength;
148 const size_t sizeOfBuffer = (pszPathOutLength + 1) * 2;
149 PSTR pszPathOut = calloc(sizeOfBuffer, 2);
152 return E_OUTOFMEMORY;
155 (void)sprintf_s(pszPathOut, sizeOfBuffer,
"%s%s", pszPathIn, pszMore);
157 (
void)sprintf_s(pszPathOut, sizeOfBuffer,
"%s%s%s", pszPathIn, CUR_PATH_SEPARATOR_STR,
160 *ppszPathOut = pszPathOut;