11 HRESULT PATH_CCH_APPEND(PWSTR pszPath,
size_t cchPath, PCWSTR pszMore)
24 if (cchPath == 0 || cchPath > PATHCCH_MAX_CCH)
27 pszMoreLength = _wcslen(pszMore);
28 pszPathLength = _wcslen(pszPath);
30 pathBackslash = (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
31 moreBackslash = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
33 if (pathBackslash && moreBackslash)
35 if ((pszPathLength + pszMoreLength - 1) < cchPath)
37 WCHAR* ptr = &pszPath[pszPathLength];
39 _wcsncat(ptr, &pszMore[1], _wcslen(&pszMore[1]));
43 else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash))
45 if ((pszPathLength + pszMoreLength) < cchPath)
47 WCHAR* ptr = &pszPath[pszPathLength];
49 _wcsncat(ptr, pszMore, _wcslen(pszMore));
53 else if (!pathBackslash && !moreBackslash)
55 if ((pszPathLength + pszMoreLength + 1) < cchPath)
57 const WCHAR sep[] = CUR_PATH_SEPARATOR_STR;
58 WCHAR* ptr = &pszPath[pszPathLength];
60 _wcsncat(ptr, sep, _wcslen(sep));
61 _wcsncat(ptr, pszMore, _wcslen(pszMore));
66 return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
71 HRESULT PATH_CCH_APPEND(PSTR pszPath,
size_t cchPath, PCSTR pszMore)
73 BOOL pathBackslash = FALSE;
74 BOOL moreBackslash = FALSE;
84 if (cchPath == 0 || cchPath > PATHCCH_MAX_CCH)
87 pszPathLength = strlen(pszPath);
88 if (pszPathLength > 0)
89 pathBackslash = (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
91 pszMoreLength = strlen(pszMore);
92 if (pszMoreLength > 0)
93 moreBackslash = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;
95 if (pathBackslash && moreBackslash)
97 if ((pszPathLength + pszMoreLength - 1) < cchPath)
99 sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength,
"%s", &pszMore[1]);
103 else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash))
105 if ((pszPathLength + pszMoreLength) < cchPath)
107 sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength,
"%s", pszMore);
111 else if (!pathBackslash && !moreBackslash)
113 if ((pszPathLength + pszMoreLength + 1) < cchPath)
115 sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, CUR_PATH_SEPARATOR_STR
"%s",
121 return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);