FreeRDP/winpr/libwinpr/path/include/PathCchAddSeparator.c

65 lines
1.1 KiB
C
Raw Normal View History

2012-10-16 20:41:16 +04:00
/*
#define DEFINE_UNICODE FALSE
2021-09-08 16:37:45 +03:00
#define CUR_PATH_SEPARATOR_CHR '\\'
2012-10-16 20:41:16 +04:00
#define PATH_CCH_ADD_SEPARATOR PathCchAddBackslashA
*/
#if DEFINE_UNICODE
HRESULT PATH_CCH_ADD_SEPARATOR(PWSTR pszPath, size_t cchPath)
{
size_t pszPathLength;
if (!pszPath)
return E_INVALIDARG;
2012-10-16 20:41:16 +04:00
pszPathLength = lstrlenW(pszPath);
2021-09-08 16:37:45 +03:00
if (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR)
2012-10-16 20:41:16 +04:00
return S_FALSE;
if (cchPath > (pszPathLength + 1))
{
2021-09-08 16:37:45 +03:00
pszPath[pszPathLength] = CUR_PATH_SEPARATOR_CHR;
2012-10-16 20:41:16 +04:00
pszPath[pszPathLength + 1] = '\0';
return S_OK;
}
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
2012-10-16 20:41:16 +04:00
}
#else
HRESULT PATH_CCH_ADD_SEPARATOR(PSTR pszPath, size_t cchPath)
{
size_t pszPathLength;
if (!pszPath)
return E_INVALIDARG;
2012-10-16 20:41:16 +04:00
pszPathLength = lstrlenA(pszPath);
2021-09-08 16:37:45 +03:00
if (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR)
2012-10-16 20:41:16 +04:00
return S_FALSE;
if (cchPath > (pszPathLength + 1))
{
2021-09-08 16:37:45 +03:00
pszPath[pszPathLength] = CUR_PATH_SEPARATOR_CHR;
2012-10-16 20:41:16 +04:00
pszPath[pszPathLength + 1] = '\0';
return S_OK;
}
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
2012-10-16 20:41:16 +04:00
}
#endif
/*
#undef DEFINE_UNICODE
2021-09-08 16:37:45 +03:00
#undef CUR_PATH_SEPARATOR_CHR
2012-10-16 20:41:16 +04:00
#undef PATH_CCH_ADD_SEPARATOR
*/