FreeRDP/winpr/libwinpr/path/include/PathCchAppend.c
akallabeth 1c84690c2f
Fixes from tests (#7308)
* Fixed memory leak in tls_verify_certificate

* Fixed missing NULL checks

* Fixed missing checks for FreeRDP_DeactivateClientDecoding

* Added WINPR_ASSERT for client common new/free

* Added /disable-output switch to deactivate client decoding

Allows low resource remote connections that do not require visual
feedback. (e.g. load testing/...)
2021-09-21 09:56:56 +02:00

127 lines
2.9 KiB
C

/*
#define DEFINE_UNICODE FALSE
#define CUR_PATH_SEPARATOR_CHR '\\'
#define CUR_PATH_SEPARATOR_STR "\\"
#define PATH_CCH_APPEND PathCchAppendA
*/
#if DEFINE_UNICODE
HRESULT PATH_CCH_APPEND(PWSTR pszPath, size_t cchPath, PCWSTR pszMore)
{
#ifdef _WIN32
BOOL pathBackslash;
BOOL moreBackslash;
size_t pszMoreLength;
size_t pszPathLength;
if (!pszPath)
return E_INVALIDARG;
if (!pszMore)
return E_INVALIDARG;
if (cchPath == 0 || cchPath > PATHCCH_MAX_CCH)
return E_INVALIDARG;
pszMoreLength = lstrlenW(pszMore);
pszPathLength = lstrlenW(pszPath);
pathBackslash = (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
moreBackslash = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
if (pathBackslash && moreBackslash)
{
if ((pszPathLength + pszMoreLength - 1) < cchPath)
{
swprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, L"%s", &pszMore[1]);
return S_OK;
}
}
else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash))
{
if ((pszPathLength + pszMoreLength) < cchPath)
{
swprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, L"%s", pszMore);
return S_OK;
}
}
else if (!pathBackslash && !moreBackslash)
{
if ((pszPathLength + pszMoreLength + 1) < cchPath)
{
swprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength,
CUR_PATH_SEPARATOR_STR L"%s", pszMore);
return S_OK;
}
}
#endif
return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
}
#else
HRESULT PATH_CCH_APPEND(PSTR pszPath, size_t cchPath, PCSTR pszMore)
{
BOOL pathBackslash = FALSE;
BOOL moreBackslash = FALSE;
size_t pszMoreLength;
size_t pszPathLength;
if (!pszPath)
return E_INVALIDARG;
if (!pszMore)
return E_INVALIDARG;
if (cchPath == 0 || cchPath > PATHCCH_MAX_CCH)
return E_INVALIDARG;
pszPathLength = lstrlenA(pszPath);
if (pszPathLength > 0)
pathBackslash = (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
pszMoreLength = lstrlenA(pszMore);
if (pszMoreLength > 0)
moreBackslash = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
if (pathBackslash && moreBackslash)
{
if ((pszPathLength + pszMoreLength - 1) < cchPath)
{
sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", &pszMore[1]);
return S_OK;
}
}
else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash))
{
if ((pszPathLength + pszMoreLength) < cchPath)
{
sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", pszMore);
return S_OK;
}
}
else if (!pathBackslash && !moreBackslash)
{
if ((pszPathLength + pszMoreLength + 1) < cchPath)
{
sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, CUR_PATH_SEPARATOR_STR "%s",
pszMore);
return S_OK;
}
}
return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
}
#endif
/*
#undef DEFINE_UNICODE
#undef CUR_PATH_SEPARATOR_CHR
#undef CUR_PATH_SEPARATOR_STR
#undef PATH_CCH_APPEND
*/