10HRESULT PATH_CCH_ADD_EXTENSION(PWSTR pszPath,
size_t cchPath, PCWSTR pszExt)
24 pszExtLength = _wcslen(pszExt);
25 pszPathLength = _wcslen(pszPath);
26 bExtDot = (pszExt[0] ==
'.') ? TRUE : FALSE;
28 pDot = _wcsrchr(pszPath,
'.');
29 pBackslash = _wcsrchr(pszPath, CUR_PATH_SEPARATOR_CHR);
31 if (pDot && pBackslash)
33 if (pDot > pBackslash)
37 if (cchPath > pszPathLength + pszExtLength + ((bExtDot) ? 0 : 1))
39 const WCHAR dot[] = {
'.',
'\0' };
40 WCHAR* ptr = &pszPath[pszPathLength];
44 _wcsncat(ptr, dot, _wcslen(dot));
45 _wcsncat(ptr, pszExt, pszExtLength);
50 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
55HRESULT PATH_CCH_ADD_EXTENSION(PSTR pszPath,
size_t cchPath, PCSTR pszExt)
63 const size_t pszExtLength = strlen(pszExt);
64 const size_t pszPathLength = strlen(pszPath);
65 const BOOL bExtDot = (pszExt[0] ==
'.') ? TRUE : FALSE;
67 const char* pDot = strrchr(pszPath,
'.');
68 const char* pBackslash = strrchr(pszPath, CUR_PATH_SEPARATOR_CHR);
70 if (pDot && pBackslash)
72 if (pDot > pBackslash)
76 if (cchPath > pszPathLength + pszExtLength + ((bExtDot) ? 0 : 1))
80 if (sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength,
"%s", pszExt) < 0)
85 if (sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength,
".%s", pszExt) < 0)
92 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);