2012-10-17 01:18:12 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
#define DEFINE_UNICODE FALSE
|
|
|
|
#define _PATH_SEPARATOR_CHR '\\'
|
|
|
|
#define _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)
|
2015-06-03 17:05:19 +03:00
|
|
|
return E_INVALIDARG;
|
2012-10-17 01:18:12 +04:00
|
|
|
|
|
|
|
if (!pszMore)
|
2015-06-03 17:05:19 +03:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (cchPath == 0 || cchPath > PATHCCH_MAX_CCH)
|
|
|
|
return E_INVALIDARG;
|
2012-10-17 01:18:12 +04:00
|
|
|
|
|
|
|
pszMoreLength = lstrlenW(pszMore);
|
|
|
|
pszPathLength = lstrlenW(pszPath);
|
|
|
|
|
|
|
|
pathBackslash = (pszPath[pszPathLength - 1] == _PATH_SEPARATOR_CHR) ? TRUE : FALSE;
|
|
|
|
moreBackslash = (pszMore[0] == _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)
|
|
|
|
{
|
2012-10-17 15:48:24 +04:00
|
|
|
swprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, _PATH_SEPARATOR_STR L"%s", pszMore);
|
2012-10-17 01:18:12 +04:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-06-03 17:05:19 +03:00
|
|
|
return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
|
2012-10-17 01:18:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
HRESULT PATH_CCH_APPEND(PSTR pszPath, size_t cchPath, PCSTR pszMore)
|
|
|
|
{
|
|
|
|
BOOL pathBackslash;
|
|
|
|
BOOL moreBackslash;
|
|
|
|
size_t pszMoreLength;
|
|
|
|
size_t pszPathLength;
|
|
|
|
|
|
|
|
if (!pszPath)
|
2015-06-03 17:05:19 +03:00
|
|
|
return E_INVALIDARG;
|
2012-10-17 01:18:12 +04:00
|
|
|
|
|
|
|
if (!pszMore)
|
2015-06-03 17:05:19 +03:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (cchPath == 0 || cchPath > PATHCCH_MAX_CCH)
|
|
|
|
return E_INVALIDARG;
|
2012-10-17 01:18:12 +04:00
|
|
|
|
|
|
|
pszMoreLength = lstrlenA(pszMore);
|
|
|
|
pszPathLength = lstrlenA(pszPath);
|
|
|
|
|
|
|
|
pathBackslash = (pszPath[pszPathLength - 1] == _PATH_SEPARATOR_CHR) ? TRUE : FALSE;
|
|
|
|
moreBackslash = (pszMore[0] == _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, _PATH_SEPARATOR_STR "%s", pszMore);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-03 17:05:19 +03:00
|
|
|
return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
|
2012-10-17 01:18:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
#undef DEFINE_UNICODE
|
|
|
|
#undef _PATH_SEPARATOR_CHR
|
|
|
|
#undef _PATH_SEPARATOR_STR
|
|
|
|
#undef PATH_CCH_APPEND
|
|
|
|
*/
|
|
|
|
|