/src/FreeRDP/winpr/libwinpr/path/include/PathCchAppend.h
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  |  | 
2  |  | /*  | 
3  |  | #define DEFINE_UNICODE    FALSE  | 
4  |  | #define CUR_PATH_SEPARATOR_CHR  '\\'  | 
5  |  | #define CUR_PATH_SEPARATOR_STR  "\\"  | 
6  |  | #define PATH_CCH_APPEND   PathCchAppendA  | 
7  |  | */  | 
8  |  |  | 
9  |  | #if DEFINE_UNICODE  | 
10  |  |  | 
11  |  | HRESULT PATH_CCH_APPEND(PWSTR pszPath, size_t cchPath, PCWSTR pszMore)  | 
12  | 0  | { | 
13  | 0  |   BOOL pathBackslash;  | 
14  | 0  |   BOOL moreBackslash;  | 
15  | 0  |   size_t pszMoreLength;  | 
16  | 0  |   size_t pszPathLength;  | 
17  |  | 
  | 
18  | 0  |   if (!pszPath)  | 
19  | 0  |     return E_INVALIDARG;  | 
20  |  |  | 
21  | 0  |   if (!pszMore)  | 
22  | 0  |     return E_INVALIDARG;  | 
23  |  |  | 
24  | 0  |   if (cchPath == 0 || cchPath > PATHCCH_MAX_CCH)  | 
25  | 0  |     return E_INVALIDARG;  | 
26  |  |  | 
27  | 0  |   pszMoreLength = _wcslen(pszMore);  | 
28  | 0  |   pszPathLength = _wcslen(pszPath);  | 
29  |  | 
  | 
30  | 0  |   pathBackslash = (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;  | 
31  | 0  |   moreBackslash = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;  | 
32  |  | 
  | 
33  | 0  |   if (pathBackslash && moreBackslash)  | 
34  | 0  |   { | 
35  | 0  |     if ((pszPathLength + pszMoreLength - 1) < cchPath)  | 
36  | 0  |     { | 
37  | 0  |       WCHAR* ptr = &pszPath[pszPathLength];  | 
38  | 0  |       *ptr = '\0';  | 
39  | 0  |       _wcsncat(ptr, &pszMore[1], _wcslen(&pszMore[1]));  | 
40  | 0  |       return S_OK;  | 
41  | 0  |     }  | 
42  | 0  |   }  | 
43  | 0  |   else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash))  | 
44  | 0  |   { | 
45  | 0  |     if ((pszPathLength + pszMoreLength) < cchPath)  | 
46  | 0  |     { | 
47  | 0  |       WCHAR* ptr = &pszPath[pszPathLength];  | 
48  | 0  |       *ptr = '\0';  | 
49  | 0  |       _wcsncat(ptr, pszMore, _wcslen(pszMore));  | 
50  | 0  |       return S_OK;  | 
51  | 0  |     }  | 
52  | 0  |   }  | 
53  | 0  |   else if (!pathBackslash && !moreBackslash)  | 
54  | 0  |   { | 
55  | 0  |     if ((pszPathLength + pszMoreLength + 1) < cchPath)  | 
56  | 0  |     { | 
57  | 0  |       const WCHAR sep[] = CUR_PATH_SEPARATOR_STR;  | 
58  | 0  |       WCHAR* ptr = &pszPath[pszPathLength];  | 
59  | 0  |       *ptr = '\0';  | 
60  | 0  |       _wcsncat(ptr, sep, _wcslen(sep));  | 
61  | 0  |       _wcsncat(ptr, pszMore, _wcslen(pszMore));  | 
62  | 0  |       return S_OK;  | 
63  | 0  |     }  | 
64  | 0  |   }  | 
65  |  |  | 
66  | 0  |   return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);  | 
67  | 0  | } Unexecuted instantiation: PathCchAppendW Unexecuted instantiation: UnixPathCchAppendW Unexecuted instantiation: NativePathCchAppendW  | 
68  |  |  | 
69  |  | #else  | 
70  |  |  | 
71  |  | HRESULT PATH_CCH_APPEND(PSTR pszPath, size_t cchPath, PCSTR pszMore)  | 
72  | 79.6k  | { | 
73  | 79.6k  |   BOOL pathBackslash = FALSE;  | 
74  | 79.6k  |   BOOL moreBackslash = FALSE;  | 
75  | 79.6k  |   size_t pszMoreLength;  | 
76  | 79.6k  |   size_t pszPathLength;  | 
77  |  |  | 
78  | 79.6k  |   if (!pszPath)  | 
79  | 0  |     return E_INVALIDARG;  | 
80  |  |  | 
81  | 79.6k  |   if (!pszMore)  | 
82  | 0  |     return E_INVALIDARG;  | 
83  |  |  | 
84  | 79.6k  |   if (cchPath == 0 || cchPath > PATHCCH_MAX_CCH)  | 
85  | 0  |     return E_INVALIDARG;  | 
86  |  |  | 
87  | 79.6k  |   pszPathLength = strlen(pszPath);  | 
88  | 79.6k  |   if (pszPathLength > 0)  | 
89  | 79.6k  |     pathBackslash = (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;  | 
90  |  |  | 
91  | 79.6k  |   pszMoreLength = strlen(pszMore);  | 
92  | 79.6k  |   if (pszMoreLength > 0)  | 
93  | 79.6k  |     moreBackslash = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;  | 
94  |  |  | 
95  | 79.6k  |   if (pathBackslash && moreBackslash)  | 
96  | 0  |   { | 
97  | 0  |     if ((pszPathLength + pszMoreLength - 1) < cchPath)  | 
98  | 0  |     { | 
99  | 0  |       sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", &pszMore[1]);  | 
100  | 0  |       return S_OK;  | 
101  | 0  |     }  | 
102  | 0  |   }  | 
103  | 79.6k  |   else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash))  | 
104  | 0  |   { | 
105  | 0  |     if ((pszPathLength + pszMoreLength) < cchPath)  | 
106  | 0  |     { | 
107  | 0  |       sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", pszMore);  | 
108  | 0  |       return S_OK;  | 
109  | 0  |     }  | 
110  | 0  |   }  | 
111  | 79.6k  |   else if (!pathBackslash && !moreBackslash)  | 
112  | 79.6k  |   { | 
113  | 79.6k  |     if ((pszPathLength + pszMoreLength + 1) < cchPath)  | 
114  | 79.6k  |     { | 
115  | 79.6k  |       sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, CUR_PATH_SEPARATOR_STR "%s",  | 
116  | 79.6k  |                 pszMore);  | 
117  | 79.6k  |       return S_OK;  | 
118  | 79.6k  |     }  | 
119  | 79.6k  |   }  | 
120  |  |  | 
121  | 0  |   return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);  | 
122  | 79.6k  | } Unexecuted instantiation: PathCchAppendA Unexecuted instantiation: UnixPathCchAppendA Line  | Count  | Source  |  72  | 79.6k  | { |  73  | 79.6k  |   BOOL pathBackslash = FALSE;  |  74  | 79.6k  |   BOOL moreBackslash = FALSE;  |  75  | 79.6k  |   size_t pszMoreLength;  |  76  | 79.6k  |   size_t pszPathLength;  |  77  |  |  |  78  | 79.6k  |   if (!pszPath)  |  79  | 0  |     return E_INVALIDARG;  |  80  |  |  |  81  | 79.6k  |   if (!pszMore)  |  82  | 0  |     return E_INVALIDARG;  |  83  |  |  |  84  | 79.6k  |   if (cchPath == 0 || cchPath > PATHCCH_MAX_CCH)  |  85  | 0  |     return E_INVALIDARG;  |  86  |  |  |  87  | 79.6k  |   pszPathLength = strlen(pszPath);  |  88  | 79.6k  |   if (pszPathLength > 0)  |  89  | 79.6k  |     pathBackslash = (pszPath[pszPathLength - 1] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;  |  90  |  |  |  91  | 79.6k  |   pszMoreLength = strlen(pszMore);  |  92  | 79.6k  |   if (pszMoreLength > 0)  |  93  | 79.6k  |     moreBackslash = (pszMore[0] == CUR_PATH_SEPARATOR_CHR) ? TRUE : FALSE;  |  94  |  |  |  95  | 79.6k  |   if (pathBackslash && moreBackslash)  |  96  | 0  |   { |  97  | 0  |     if ((pszPathLength + pszMoreLength - 1) < cchPath)  |  98  | 0  |     { |  99  | 0  |       sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", &pszMore[1]);  |  100  | 0  |       return S_OK;  |  101  | 0  |     }  |  102  | 0  |   }  |  103  | 79.6k  |   else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash))  |  104  | 0  |   { |  105  | 0  |     if ((pszPathLength + pszMoreLength) < cchPath)  |  106  | 0  |     { |  107  | 0  |       sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", pszMore);  |  108  | 0  |       return S_OK;  |  109  | 0  |     }  |  110  | 0  |   }  |  111  | 79.6k  |   else if (!pathBackslash && !moreBackslash)  |  112  | 79.6k  |   { |  113  | 79.6k  |     if ((pszPathLength + pszMoreLength + 1) < cchPath)  |  114  | 79.6k  |     { |  115  | 79.6k  |       sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, CUR_PATH_SEPARATOR_STR "%s",  |  116  | 79.6k  |                 pszMore);  |  117  | 79.6k  |       return S_OK;  |  118  | 79.6k  |     }  |  119  | 79.6k  |   }  |  120  |  |  |  121  | 0  |   return HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);  |  122  | 79.6k  | }  |  
  | 
123  |  |  | 
124  |  | #endif  | 
125  |  |  | 
126  |  | /*  | 
127  |  | #undef DEFINE_UNICODE  | 
128  |  | #undef CUR_PATH_SEPARATOR_CHR  | 
129  |  | #undef CUR_PATH_SEPARATOR_STR  | 
130  |  | #undef PATH_CCH_APPEND  | 
131  |  | */  |