1 /**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the w64 mingw-runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6 #ifndef _STRSAFE_H_INCLUDED_
7 #define _STRSAFE_H_INCLUDED_
8
9 #include <_mingw_unicode.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdarg.h>
13 #include <specstrings.h>
14
15 #ifdef __clang__
16 #pragma clang diagnostic push
17 #pragma clang diagnostic ignored "-Wignored-attributes"
18 #endif
19
20 #ifndef _SIZE_T_DEFINED
21 #define _SIZE_T_DEFINED
22 #undef size_t
23 #ifdef _WIN64
24 __MINGW_EXTENSION typedef unsigned __int64 size_t;
25 #else
26 typedef unsigned int size_t;
27 #endif
28 #endif
29
30 #ifndef _SSIZE_T_DEFINED
31 #define _SSIZE_T_DEFINED
32 #undef ssize_t
33 #ifdef _WIN64
34 __MINGW_EXTENSION typedef __int64 ssize_t;
35 #else
36 typedef int ssize_t;
37 #endif
38 #endif
39
40 #ifndef _WCHAR_T_DEFINED
41 #define _WCHAR_T_DEFINED
42 typedef unsigned short wchar_t;
43 #endif
44
45 #ifndef _HRESULT_DEFINED
46 #define _HRESULT_DEFINED
47 typedef long HRESULT;
48 #endif
49
50 #ifndef SUCCEEDED
51 #define SUCCEEDED(hr) ((HRESULT)(hr) >= 0)
52 #endif
53
54 #ifndef FAILED
55 #define FAILED(hr) ((HRESULT)(hr) < 0)
56 #endif
57
58 #ifndef S_OK
59 #define S_OK ((HRESULT)0x00000000L)
60 #endif
61
62 #ifndef C_ASSERT
63 #ifdef _MSC_VER
64 # define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
65 #else
66 # define C_ASSERT(e) extern void __C_ASSERT__(int [(e)?1:-1])
67 #endif
68 #endif /* C_ASSERT */
69
70 #ifdef __cplusplus
71 #define _STRSAFE_EXTERN_C extern "C"
72 #else
73 #define _STRSAFE_EXTERN_C extern
74 #endif
75
76 #ifndef WINAPI
77 #define WINAPI __stdcall
78 #endif
79
80 #define STRSAFEAPI static __inline HRESULT WINAPI
81 #define STRSAFE_INLINE_API __CRT_INLINE HRESULT WINAPI
82
83 #define STRSAFE_MAX_CCH 2147483647
84
85 #ifndef _NTSTRSAFE_H_INCLUDED_
86 #define STRSAFE_IGNORE_NULLS 0x00000100
87 #define STRSAFE_FILL_BEHIND_NULL 0x00000200
88 #define STRSAFE_FILL_ON_FAILURE 0x00000400
89 #define STRSAFE_NULL_ON_FAILURE 0x00000800
90 #define STRSAFE_NO_TRUNCATION 0x00001000
91 #define STRSAFE_IGNORE_NULL_UNICODE_STRINGS 0x00010000
92 #define STRSAFE_UNICODE_STRING_DEST_NULL_TERMINATED 0x00020000
93
94 #define STRSAFE_VALID_FLAGS (0x000000FF | STRSAFE_IGNORE_NULLS | STRSAFE_FILL_BEHIND_NULL | STRSAFE_FILL_ON_FAILURE | STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)
95 #define STRSAFE_UNICODE_STRING_VALID_FLAGS (STRSAFE_VALID_FLAGS | STRSAFE_IGNORE_NULL_UNICODE_STRINGS | STRSAFE_UNICODE_STRING_DEST_NULL_TERMINATED)
96
97 #define STRSAFE_FILL_BYTE(x) ((STRSAFE_DWORD)(((x) & 0x000000FF) | STRSAFE_FILL_BEHIND_NULL))
98 #define STRSAFE_FAILURE_BYTE(x) ((STRSAFE_DWORD)(((x) & 0x000000FF) | STRSAFE_FILL_ON_FAILURE))
99
100 #define STRSAFE_GET_FILL_PATTERN(dwFlags) ((int)((dwFlags) & 0x000000FF))
101 #endif
102
103 #define STRSAFE_E_INSUFFICIENT_BUFFER ((HRESULT)0x8007007AL)
104 #define STRSAFE_E_INVALID_PARAMETER ((HRESULT)0x80070057L)
105 #define STRSAFE_E_END_OF_FILE ((HRESULT)0x80070026L)
106
107 typedef char *STRSAFE_LPSTR;
108 typedef const char *STRSAFE_LPCSTR;
109 typedef wchar_t *STRSAFE_LPWSTR;
110 typedef const wchar_t *STRSAFE_LPCWSTR;
111
112 typedef ULONG STRSAFE_DWORD;
113
114 STRSAFEAPI StringCopyWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc);
115 STRSAFEAPI StringCopyWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc);
116 STRSAFEAPI StringCopyExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
117 STRSAFEAPI StringCopyExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
118 STRSAFEAPI StringCopyNWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToCopy);
119 STRSAFEAPI StringCopyNWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToCopy);
120 STRSAFEAPI StringCopyNExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cchToCopy,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
121 STRSAFEAPI StringCopyNExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cchToCopy,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
122 STRSAFEAPI StringCatWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc);
123 STRSAFEAPI StringCatWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc);
124 STRSAFEAPI StringCatExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
125 STRSAFEAPI StringCatExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
126 STRSAFEAPI StringCatNWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend);
127 STRSAFEAPI StringCatNWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToAppend);
128 STRSAFEAPI StringCatNExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
129 STRSAFEAPI StringCatNExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cchToAppend,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
130 STRSAFEAPI StringVPrintfWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszFormat,va_list argList);
131 STRSAFEAPI StringVPrintfWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszFormat,va_list argList);
132 STRSAFEAPI StringVPrintfExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCSTR pszFormat,va_list argList);
133 STRSAFEAPI StringVPrintfExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCWSTR pszFormat,va_list argList);
134 STRSAFEAPI StringLengthWorkerA(STRSAFE_LPCSTR psz,size_t cchMax,size_t *pcchLength);
135 STRSAFEAPI StringLengthWorkerW(STRSAFE_LPCWSTR psz,size_t cchMax,size_t *pcchLength);
136 STRSAFE_INLINE_API StringGetsExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
137 STRSAFE_INLINE_API StringGetsExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
138
139 #define StringCchCopy __MINGW_NAME_AW(StringCchCopy)
140
141 STRSAFEAPI StringCchCopyA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc);
142 STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc);
143
144 #ifndef __CRT__NO_INLINE
StringCchCopyA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc)145 STRSAFEAPI StringCchCopyA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc) {
146 return (cchDest > STRSAFE_MAX_CCH ? STRSAFE_E_INVALID_PARAMETER : StringCopyWorkerA(pszDest,cchDest,pszSrc));
147 }
148
StringCchCopyW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc)149 STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc) {
150 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
151 return StringCopyWorkerW(pszDest,cchDest,pszSrc);
152 }
153 #endif /* !__CRT__NO_INLINE */
154
155 #define StringCbCopy __MINGW_NAME_AW(StringCbCopy)
156
157 STRSAFEAPI StringCbCopyA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc);
158 STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc);
159
160 #ifndef __CRT__NO_INLINE
StringCbCopyA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc)161 STRSAFEAPI StringCbCopyA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc) {
162 if(cbDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
163 return StringCopyWorkerA(pszDest,cbDest,pszSrc);
164 }
165
StringCbCopyW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc)166 STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc) {
167 size_t cchDest = cbDest / sizeof(wchar_t);
168 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
169 return StringCopyWorkerW(pszDest,cchDest,pszSrc);
170 }
171 #endif /* !__CRT__NO_INLINE */
172
173 #define StringCchCopyEx __MINGW_NAME_AW(StringCchCopyEx)
174
175 STRSAFEAPI StringCchCopyExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
176 STRSAFEAPI StringCchCopyExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
177
178 #ifndef __CRT__NO_INLINE
StringCchCopyExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)179 STRSAFEAPI StringCchCopyExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
180 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
181 return StringCopyExWorkerA(pszDest,cchDest,cchDest,pszSrc,ppszDestEnd,pcchRemaining,dwFlags);
182 }
183
StringCchCopyExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)184 STRSAFEAPI StringCchCopyExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
185 size_t cbDest;
186 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
187 cbDest = cchDest * sizeof(wchar_t);
188 return StringCopyExWorkerW(pszDest,cchDest,cbDest,pszSrc,ppszDestEnd,pcchRemaining,dwFlags);
189 }
190 #endif /* !__CRT__NO_INLINE */
191
192 #define StringCbCopyEx __MINGW_NAME_AW(StringCbCopyEx)
193
194 STRSAFEAPI StringCbCopyExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags);
195 STRSAFEAPI StringCbCopyExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags);
196
197 #ifndef __CRT__NO_INLINE
StringCbCopyExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR * ppszDestEnd,size_t * pcbRemaining,STRSAFE_DWORD dwFlags)198 STRSAFEAPI StringCbCopyExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags) {
199 HRESULT hr;
200 size_t cchRemaining = 0;
201 if(cbDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
202 hr = StringCopyExWorkerA(pszDest,cbDest,cbDest,pszSrc,ppszDestEnd,&cchRemaining,dwFlags);
203 if(SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER) {
204 if(pcbRemaining)
205 *pcbRemaining = (cchRemaining*sizeof(char)) + (cbDest % sizeof(char));
206 }
207 return hr;
208 }
209
StringCbCopyExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcbRemaining,STRSAFE_DWORD dwFlags)210 STRSAFEAPI StringCbCopyExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags) {
211 HRESULT hr;
212 size_t cchDest = cbDest / sizeof(wchar_t);
213 size_t cchRemaining = 0;
214
215 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
216 hr = StringCopyExWorkerW(pszDest,cchDest,cbDest,pszSrc,ppszDestEnd,&cchRemaining,dwFlags);
217 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER)) {
218 if(pcbRemaining)
219 *pcbRemaining = (cchRemaining*sizeof(wchar_t)) + (cbDest % sizeof(wchar_t));
220 }
221 return hr;
222 }
223 #endif /* !__CRT__NO_INLINE */
224
225 STRSAFEAPI StringCchCopyNA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToCopy);
226 STRSAFEAPI StringCchCopyNW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToCopy);
227 #define StringCchCopyN __MINGW_NAME_AW(StringCchCopyN)
228
229 #ifndef __CRT__NO_INLINE
StringCchCopyNA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToCopy)230 STRSAFEAPI StringCchCopyNA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToCopy) {
231 if(cchDest > STRSAFE_MAX_CCH || cchToCopy > STRSAFE_MAX_CCH)
232 return STRSAFE_E_INVALID_PARAMETER;
233 return StringCopyNWorkerA(pszDest,cchDest,pszSrc,cchToCopy);
234 }
235
StringCchCopyNW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToCopy)236 STRSAFEAPI StringCchCopyNW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToCopy) {
237 if(cchDest > STRSAFE_MAX_CCH || cchToCopy > STRSAFE_MAX_CCH)
238 return STRSAFE_E_INVALID_PARAMETER;
239 return StringCopyNWorkerW(pszDest,cchDest,pszSrc,cchToCopy);
240 }
241 #endif /* !__CRT__NO_INLINE */
242
243 STRSAFEAPI StringCbCopyNA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cbToCopy);
244 STRSAFEAPI StringCbCopyNW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cbToCopy);
245
246 #define StringCbCopyN __MINGW_NAME_AW(StringCbCopyN)
247
248 #ifndef __CRT__NO_INLINE
StringCbCopyNA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cbToCopy)249 STRSAFEAPI StringCbCopyNA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cbToCopy) {
250 if(cbDest > STRSAFE_MAX_CCH || cbToCopy > STRSAFE_MAX_CCH)
251 return STRSAFE_E_INVALID_PARAMETER;
252 return StringCopyNWorkerA(pszDest,cbDest,pszSrc,cbToCopy);
253 }
254
StringCbCopyNW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cbToCopy)255 STRSAFEAPI StringCbCopyNW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cbToCopy) {
256 size_t cchDest = cbDest / sizeof(wchar_t);
257 size_t cchToCopy = cbToCopy / sizeof(wchar_t);
258 if(cchDest > STRSAFE_MAX_CCH || cchToCopy > STRSAFE_MAX_CCH)
259 return STRSAFE_E_INVALID_PARAMETER;
260 return StringCopyNWorkerW(pszDest,cchDest,pszSrc,cchToCopy);
261 }
262 #endif /* !__CRT__NO_INLINE */
263
264 STRSAFEAPI StringCchCopyNExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToCopy,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
265 STRSAFEAPI StringCchCopyNExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToCopy,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
266
267 #define StringCchCopyNEx __MINGW_NAME_AW(StringCchCopyNEx)
268
269 #ifndef __CRT__NO_INLINE
StringCchCopyNExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToCopy,STRSAFE_LPSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)270 STRSAFEAPI StringCchCopyNExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToCopy,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
271 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
272 return StringCopyNExWorkerA(pszDest,cchDest,cchDest,pszSrc,cchToCopy,ppszDestEnd,pcchRemaining,dwFlags);
273 }
274
StringCchCopyNExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToCopy,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)275 STRSAFEAPI StringCchCopyNExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToCopy,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
276 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
277 return StringCopyNExWorkerW(pszDest,cchDest,cchDest * sizeof(wchar_t),pszSrc,cchToCopy,ppszDestEnd,pcchRemaining,dwFlags);
278 }
279 #endif /* !__CRT__NO_INLINE */
280
281 STRSAFEAPI StringCbCopyNExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cbToCopy,STRSAFE_LPSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags);
282 STRSAFEAPI StringCbCopyNExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cbToCopy,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags);
283
284 #define StringCbCopyNEx __MINGW_NAME_AW(StringCbCopyNEx)
285
286 #ifndef __CRT__NO_INLINE
StringCbCopyNExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cbToCopy,STRSAFE_LPSTR * ppszDestEnd,size_t * pcbRemaining,STRSAFE_DWORD dwFlags)287 STRSAFEAPI StringCbCopyNExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cbToCopy,STRSAFE_LPSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags) {
288 HRESULT hr;
289 size_t cchRemaining = 0;
290 if(cbDest > STRSAFE_MAX_CCH)
291 hr = STRSAFE_E_INVALID_PARAMETER;
292 else
293 hr = StringCopyNExWorkerA(pszDest,cbDest,cbDest,pszSrc,cbToCopy,ppszDestEnd,&cchRemaining,dwFlags);
294 if((SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER) && pcbRemaining)
295 *pcbRemaining = cchRemaining;
296 return hr;
297 }
298
StringCbCopyNExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cbToCopy,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcbRemaining,STRSAFE_DWORD dwFlags)299 STRSAFEAPI StringCbCopyNExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cbToCopy,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags) {
300 HRESULT hr;
301 size_t cchDest;
302 size_t cchToCopy;
303 size_t cchRemaining = 0;
304 cchDest = cbDest / sizeof(wchar_t);
305 cchToCopy = cbToCopy / sizeof(wchar_t);
306 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
307 else hr = StringCopyNExWorkerW(pszDest,cchDest,cbDest,pszSrc,cchToCopy,ppszDestEnd,&cchRemaining,dwFlags);
308 if((SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER) && pcbRemaining)
309 *pcbRemaining = (cchRemaining*sizeof(wchar_t)) + (cbDest % sizeof(wchar_t));
310 return hr;
311 }
312 #endif /* !__CRT__NO_INLINE */
313
314 STRSAFEAPI StringCchCatA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc);
315 STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc);
316
317 #define StringCchCat __MINGW_NAME_AW(StringCchCat)
318
319 #ifndef __CRT__NO_INLINE
StringCchCatA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc)320 STRSAFEAPI StringCchCatA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc) {
321 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
322 return StringCatWorkerA(pszDest,cchDest,pszSrc);
323 }
324
StringCchCatW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc)325 STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc) {
326 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
327 return StringCatWorkerW(pszDest,cchDest,pszSrc);
328 }
329 #endif /* !__CRT__NO_INLINE */
330
331 STRSAFEAPI StringCbCatA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc);
332 STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc);
333
334 #define StringCbCat __MINGW_NAME_AW(StringCbCat)
335
336 #ifndef __CRT__NO_INLINE
StringCbCatA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc)337 STRSAFEAPI StringCbCatA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc) {
338 if(cbDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
339 return StringCatWorkerA(pszDest,cbDest,pszSrc);
340 }
341
StringCbCatW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc)342 STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc) {
343 size_t cchDest = cbDest / sizeof(wchar_t);
344 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
345 return StringCatWorkerW(pszDest,cchDest,pszSrc);
346 }
347 #endif /* !__CRT__NO_INLINE */
348
349 STRSAFEAPI StringCchCatExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
350 STRSAFEAPI StringCchCatExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
351
352 #define StringCchCatEx __MINGW_NAME_AW(StringCchCatEx)
353
354 #ifndef __CRT__NO_INLINE
StringCchCatExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)355 STRSAFEAPI StringCchCatExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
356 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
357 return StringCatExWorkerA(pszDest,cchDest,cchDest,pszSrc,ppszDestEnd,pcchRemaining,dwFlags);
358 }
359
StringCchCatExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)360 STRSAFEAPI StringCchCatExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
361 size_t cbDest = cchDest*sizeof(wchar_t);
362 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
363 return StringCatExWorkerW(pszDest,cchDest,cbDest,pszSrc,ppszDestEnd,pcchRemaining,dwFlags);
364 }
365 #endif /* !__CRT__NO_INLINE */
366
367 STRSAFEAPI StringCbCatExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags);
368 STRSAFEAPI StringCbCatExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags);
369
370 #define StringCbCatEx __MINGW_NAME_AW(StringCbCatEx)
371
372 #ifndef __CRT__NO_INLINE
StringCbCatExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR * ppszDestEnd,size_t * pcbRemaining,STRSAFE_DWORD dwFlags)373 STRSAFEAPI StringCbCatExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags) {
374 HRESULT hr;
375 size_t cchRemaining = 0;
376 if(cbDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
377 else hr = StringCatExWorkerA(pszDest,cbDest,cbDest,pszSrc,ppszDestEnd,&cchRemaining,dwFlags);
378 if((SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER) && pcbRemaining)
379 *pcbRemaining = (cchRemaining*sizeof(char)) + (cbDest % sizeof(char));
380 return hr;
381 }
382
StringCbCatExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcbRemaining,STRSAFE_DWORD dwFlags)383 STRSAFEAPI StringCbCatExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags) {
384 HRESULT hr;
385 size_t cchDest = cbDest / sizeof(wchar_t);
386 size_t cchRemaining = 0;
387
388 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
389 else hr = StringCatExWorkerW(pszDest,cchDest,cbDest,pszSrc,ppszDestEnd,&cchRemaining,dwFlags);
390 if((SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER) && pcbRemaining)
391 *pcbRemaining = (cchRemaining*sizeof(wchar_t)) + (cbDest % sizeof(wchar_t));
392 return hr;
393 }
394 #endif /* !__CRT__NO_INLINE */
395
396 STRSAFEAPI StringCchCatNA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend);
397 STRSAFEAPI StringCchCatNW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToAppend);
398
399 #define StringCchCatN __MINGW_NAME_AW(StringCchCatN)
400
401 #ifndef __CRT__NO_INLINE
StringCchCatNA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend)402 STRSAFEAPI StringCchCatNA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend) {
403 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
404 return StringCatNWorkerA(pszDest,cchDest,pszSrc,cchToAppend);
405 }
406
StringCchCatNW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToAppend)407 STRSAFEAPI StringCchCatNW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToAppend) {
408 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
409 return StringCatNWorkerW(pszDest,cchDest,pszSrc,cchToAppend);
410 }
411 #endif /* !__CRT__NO_INLINE */
412
413 STRSAFEAPI StringCbCatNA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cbToAppend);
414 STRSAFEAPI StringCbCatNW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cbToAppend);
415
416 #define StringCbCatN __MINGW_NAME_AW(StringCbCatN)
417
418 #ifndef __CRT__NO_INLINE
StringCbCatNA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cbToAppend)419 STRSAFEAPI StringCbCatNA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cbToAppend) {
420 if(cbDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
421 return StringCatNWorkerA(pszDest,cbDest,pszSrc,cbToAppend);
422 }
423
StringCbCatNW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cbToAppend)424 STRSAFEAPI StringCbCatNW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cbToAppend) {
425 size_t cchDest = cbDest / sizeof(wchar_t);
426 size_t cchToAppend = cbToAppend / sizeof(wchar_t);
427
428 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
429 return StringCatNWorkerW(pszDest,cchDest,pszSrc,cchToAppend);
430 }
431 #endif /* !__CRT__NO_INLINE */
432
433 STRSAFEAPI StringCchCatNExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
434 STRSAFEAPI StringCchCatNExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToAppend,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
435
436 #define StringCchCatNEx __MINGW_NAME_AW(StringCchCatNEx)
437
438 #ifndef __CRT__NO_INLINE
StringCchCatNExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend,STRSAFE_LPSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)439 STRSAFEAPI StringCchCatNExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
440 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
441 return StringCatNExWorkerA(pszDest,cchDest,cchDest,pszSrc,cchToAppend,ppszDestEnd,pcchRemaining,dwFlags);
442 }
443
StringCchCatNExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToAppend,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)444 STRSAFEAPI StringCchCatNExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToAppend,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
445 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
446 return StringCatNExWorkerW(pszDest,cchDest,(cchDest*sizeof(wchar_t)),pszSrc,cchToAppend,ppszDestEnd,pcchRemaining,dwFlags);
447 }
448 #endif
449
450 STRSAFEAPI StringCbCatNExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cbToAppend,STRSAFE_LPSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags);
451 STRSAFEAPI StringCbCatNExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cbToAppend,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags);
452
453 #define StringCbCatNEx __MINGW_NAME_AW(StringCbCatNEx)
454
455 #ifndef __CRT__NO_INLINE
StringCbCatNExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cbToAppend,STRSAFE_LPSTR * ppszDestEnd,size_t * pcbRemaining,STRSAFE_DWORD dwFlags)456 STRSAFEAPI StringCbCatNExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cbToAppend,STRSAFE_LPSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags) {
457 HRESULT hr;
458 size_t cchRemaining = 0;
459 if(cbDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
460 else hr = StringCatNExWorkerA(pszDest,cbDest,cbDest,pszSrc,cbToAppend,ppszDestEnd,&cchRemaining,dwFlags);
461 if((SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER) && pcbRemaining)
462 *pcbRemaining = (cchRemaining*sizeof(char)) + (cbDest % sizeof(char));
463 return hr;
464 }
465
StringCbCatNExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cbToAppend,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcbRemaining,STRSAFE_DWORD dwFlags)466 STRSAFEAPI StringCbCatNExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cbToAppend,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags) {
467 HRESULT hr;
468 size_t cchDest = cbDest / sizeof(wchar_t);
469 size_t cchToAppend = cbToAppend / sizeof(wchar_t);
470 size_t cchRemaining = 0;
471 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
472 else hr = StringCatNExWorkerW(pszDest,cchDest,cbDest,pszSrc,cchToAppend,ppszDestEnd,&cchRemaining,dwFlags);
473 if((SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER) && pcbRemaining)
474 *pcbRemaining = (cchRemaining*sizeof(wchar_t)) + (cbDest % sizeof(wchar_t));
475 return hr;
476 }
477 #endif /* !__CRT__NO_INLINE */
478
479 STRSAFEAPI StringCchVPrintfA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszFormat,va_list argList);
480 STRSAFEAPI StringCchVPrintfW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszFormat,va_list argList);
481
482 #define StringCchVPrintf __MINGW_NAME_AW(StringCchVPrintf)
483
484 #ifndef __CRT__NO_INLINE
StringCchVPrintfA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszFormat,va_list argList)485 STRSAFEAPI StringCchVPrintfA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszFormat,va_list argList) {
486 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
487 return StringVPrintfWorkerA(pszDest,cchDest,pszFormat,argList);
488 }
489
StringCchVPrintfW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszFormat,va_list argList)490 STRSAFEAPI StringCchVPrintfW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszFormat,va_list argList) {
491 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
492 return StringVPrintfWorkerW(pszDest,cchDest,pszFormat,argList);
493 }
494 #endif /* !__CRT__NO_INLINE */
495
496 STRSAFEAPI StringCbVPrintfA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszFormat,va_list argList);
497 STRSAFEAPI StringCbVPrintfW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszFormat,va_list argList);
498
499 #define StringCbVPrintf __MINGW_NAME_AW(StringCbVPrintf)
500
501 #ifndef __CRT__NO_INLINE
StringCbVPrintfA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszFormat,va_list argList)502 STRSAFEAPI StringCbVPrintfA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszFormat,va_list argList) {
503 if(cbDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
504 return StringVPrintfWorkerA(pszDest,cbDest,pszFormat,argList);
505 }
506
StringCbVPrintfW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszFormat,va_list argList)507 STRSAFEAPI StringCbVPrintfW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszFormat,va_list argList) {
508 size_t cchDest = cbDest / sizeof(wchar_t);
509 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
510 return StringVPrintfWorkerW(pszDest,cchDest,pszFormat,argList);
511 }
512 #endif /* !__CRT__NO_INLINE */
513
514 STRSAFEAPI StringCchPrintfA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszFormat,...);
515 STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszFormat,...);
516
517 #define StringCchPrintf __MINGW_NAME_AW(StringCchPrintf)
518
519 #ifndef __CRT__NO_INLINE
StringCchPrintfA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszFormat,...)520 STRSAFEAPI StringCchPrintfA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszFormat,...) {
521 HRESULT hr;
522 va_list argList;
523 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
524 va_start(argList,pszFormat);
525 hr = StringVPrintfWorkerA(pszDest,cchDest,pszFormat,argList);
526 va_end(argList);
527 return hr;
528 }
529
StringCchPrintfW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszFormat,...)530 STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszFormat,...) {
531 HRESULT hr;
532 va_list argList;
533 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
534 va_start(argList,pszFormat);
535 hr = StringVPrintfWorkerW(pszDest,cchDest,pszFormat,argList);
536 va_end(argList);
537 return hr;
538 }
539 #endif /* !__CRT__NO_INLINE */
540
541 STRSAFEAPI StringCbPrintfA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszFormat,...);
542 STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszFormat,...);
543
544 #define StringCbPrintf __MINGW_NAME_AW(StringCbPrintf)
545
546 #ifndef __CRT__NO_INLINE
StringCbPrintfA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszFormat,...)547 STRSAFEAPI StringCbPrintfA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPCSTR pszFormat,...) {
548 HRESULT hr;
549 va_list argList;
550 if(cbDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
551 va_start(argList,pszFormat);
552 hr = StringVPrintfWorkerA(pszDest,cbDest,pszFormat,argList);
553 va_end(argList);
554 return hr;
555 }
556
StringCbPrintfW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszFormat,...)557 STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPCWSTR pszFormat,...) {
558 HRESULT hr;
559 va_list argList;
560 size_t cchDest = cbDest / sizeof(wchar_t);
561 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
562 va_start(argList,pszFormat);
563 hr = StringVPrintfWorkerW(pszDest,cchDest,pszFormat,argList);
564 va_end(argList);
565 return hr;
566 }
567 #endif /* !__CRT__NO_INLINE */
568
569 STRSAFEAPI StringCchPrintfExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCSTR pszFormat,...);
570 STRSAFEAPI StringCchPrintfExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCWSTR pszFormat,...);
571
572 #define StringCchPrintfEx __MINGW_NAME_AW(StringCchPrintfEx)
573
574 #ifndef __CRT__NO_INLINE
StringCchPrintfExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCSTR pszFormat,...)575 STRSAFEAPI StringCchPrintfExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCSTR pszFormat,...) {
576 HRESULT hr;
577 va_list argList;
578 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
579 va_start(argList,pszFormat);
580 hr = StringVPrintfExWorkerA(pszDest,cchDest,cchDest,ppszDestEnd,pcchRemaining,dwFlags,pszFormat,argList);
581 va_end(argList);
582 return hr;
583 }
584
StringCchPrintfExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCWSTR pszFormat,...)585 STRSAFEAPI StringCchPrintfExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCWSTR pszFormat,...) {
586 HRESULT hr;
587 size_t cbDest = cchDest * sizeof(wchar_t);
588 va_list argList;
589 if(cchDest > STRSAFE_MAX_CCH) return STRSAFE_E_INVALID_PARAMETER;
590 va_start(argList,pszFormat);
591 hr = StringVPrintfExWorkerW(pszDest,cchDest,cbDest,ppszDestEnd,pcchRemaining,dwFlags,pszFormat,argList);
592 va_end(argList);
593 return hr;
594 }
595 #endif /* !__CRT__NO_INLINE */
596
597 STRSAFEAPI StringCbPrintfExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCSTR pszFormat,...);
598 STRSAFEAPI StringCbPrintfExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCWSTR pszFormat,...);
599
600 #define StringCbPrintfEx __MINGW_NAME_AW(StringCbPrintfEx)
601
602 #ifndef __CRT__NO_INLINE
StringCbPrintfExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPSTR * ppszDestEnd,size_t * pcbRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCSTR pszFormat,...)603 STRSAFEAPI StringCbPrintfExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCSTR pszFormat,...) {
604 HRESULT hr;
605 size_t cchDest;
606 size_t cchRemaining = 0;
607 cchDest = cbDest / sizeof(char);
608 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
609 else {
610 va_list argList;
611 va_start(argList,pszFormat);
612 hr = StringVPrintfExWorkerA(pszDest,cchDest,cbDest,ppszDestEnd,&cchRemaining,dwFlags,pszFormat,argList);
613 va_end(argList);
614 }
615 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER)) {
616 if(pcbRemaining) {
617 *pcbRemaining = (cchRemaining*sizeof(char)) + (cbDest % sizeof(char));
618 }
619 }
620 return hr;
621 }
622
StringCbPrintfExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcbRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCWSTR pszFormat,...)623 STRSAFEAPI StringCbPrintfExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCWSTR pszFormat,...) {
624 HRESULT hr;
625 size_t cchDest;
626 size_t cchRemaining = 0;
627 cchDest = cbDest / sizeof(wchar_t);
628 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
629 else {
630 va_list argList;
631 va_start(argList,pszFormat);
632 hr = StringVPrintfExWorkerW(pszDest,cchDest,cbDest,ppszDestEnd,&cchRemaining,dwFlags,pszFormat,argList);
633 va_end(argList);
634 }
635 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER)) {
636 if(pcbRemaining) {
637 *pcbRemaining = (cchRemaining*sizeof(wchar_t)) + (cbDest % sizeof(wchar_t));
638 }
639 }
640 return hr;
641 }
642 #endif /* !__CRT__NO_INLINE */
643
644 STRSAFEAPI StringCchVPrintfExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCSTR pszFormat,va_list argList);
645 STRSAFEAPI StringCchVPrintfExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCWSTR pszFormat,va_list argList);
646
647 #define StringCchVPrintfEx __MINGW_NAME_AW(StringCchVPrintfEx)
648
649 #ifndef __CRT__NO_INLINE
StringCchVPrintfExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCSTR pszFormat,va_list argList)650 STRSAFEAPI StringCchVPrintfExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCSTR pszFormat,va_list argList) {
651 HRESULT hr;
652 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
653 else {
654 size_t cbDest;
655 cbDest = cchDest*sizeof(char);
656 hr = StringVPrintfExWorkerA(pszDest,cchDest,cbDest,ppszDestEnd,pcchRemaining,dwFlags,pszFormat,argList);
657 }
658 return hr;
659 }
660
StringCchVPrintfExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCWSTR pszFormat,va_list argList)661 STRSAFEAPI StringCchVPrintfExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCWSTR pszFormat,va_list argList) {
662 HRESULT hr;
663 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
664 else {
665 size_t cbDest;
666 cbDest = cchDest*sizeof(wchar_t);
667 hr = StringVPrintfExWorkerW(pszDest,cchDest,cbDest,ppszDestEnd,pcchRemaining,dwFlags,pszFormat,argList);
668 }
669 return hr;
670 }
671 #endif /* !__CRT__NO_INLINE */
672
673 STRSAFEAPI StringCbVPrintfExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCSTR pszFormat,va_list argList);
674 STRSAFEAPI StringCbVPrintfExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCWSTR pszFormat,va_list argList);
675
676 #define StringCbVPrintfEx __MINGW_NAME_AW(StringCbVPrintfEx)
677
678 #ifndef __CRT__NO_INLINE
StringCbVPrintfExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPSTR * ppszDestEnd,size_t * pcbRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCSTR pszFormat,va_list argList)679 STRSAFEAPI StringCbVPrintfExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCSTR pszFormat,va_list argList) {
680 HRESULT hr;
681 size_t cchDest;
682 size_t cchRemaining = 0;
683 cchDest = cbDest / sizeof(char);
684 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
685 else hr = StringVPrintfExWorkerA(pszDest,cchDest,cbDest,ppszDestEnd,&cchRemaining,dwFlags,pszFormat,argList);
686 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER)) {
687 if(pcbRemaining) {
688 *pcbRemaining = (cchRemaining*sizeof(char)) + (cbDest % sizeof(char));
689 }
690 }
691 return hr;
692 }
693
StringCbVPrintfExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcbRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCWSTR pszFormat,va_list argList)694 STRSAFEAPI StringCbVPrintfExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCWSTR pszFormat,va_list argList) {
695 HRESULT hr;
696 size_t cchDest;
697 size_t cchRemaining = 0;
698 cchDest = cbDest / sizeof(wchar_t);
699 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
700 else hr = StringVPrintfExWorkerW(pszDest,cchDest,cbDest,ppszDestEnd,&cchRemaining,dwFlags,pszFormat,argList);
701 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER)) {
702 if(pcbRemaining) {
703 *pcbRemaining = (cchRemaining*sizeof(wchar_t)) + (cbDest % sizeof(wchar_t));
704 }
705 }
706 return hr;
707 }
708 #endif /* !__CRT__NO_INLINE */
709
710 STRSAFE_INLINE_API StringCchGetsA(STRSAFE_LPSTR pszDest,size_t cchDest);
711 STRSAFE_INLINE_API StringCchGetsW(STRSAFE_LPWSTR pszDest,size_t cchDest);
712
713 #define StringCchGets __MINGW_NAME_AW(StringCchGets)
714
715 #ifndef __CRT__NO_INLINE
StringCchGetsA(STRSAFE_LPSTR pszDest,size_t cchDest)716 STRSAFE_INLINE_API StringCchGetsA(STRSAFE_LPSTR pszDest,size_t cchDest) {
717 HRESULT hr;
718 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
719 else {
720 size_t cbDest;
721 cbDest = cchDest*sizeof(char);
722 hr = StringGetsExWorkerA(pszDest,cchDest,cbDest,NULL,NULL,0);
723 }
724 return hr;
725 }
726
StringCchGetsW(STRSAFE_LPWSTR pszDest,size_t cchDest)727 STRSAFE_INLINE_API StringCchGetsW(STRSAFE_LPWSTR pszDest,size_t cchDest) {
728 HRESULT hr;
729 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
730 else {
731 size_t cbDest;
732 cbDest = cchDest*sizeof(wchar_t);
733 hr = StringGetsExWorkerW(pszDest,cchDest,cbDest,NULL,NULL,0);
734 }
735 return hr;
736 }
737 #endif /* !__CRT__NO_INLINE */
738
739 STRSAFE_INLINE_API StringCbGetsA(STRSAFE_LPSTR pszDest,size_t cbDest);
740 STRSAFE_INLINE_API StringCbGetsW(STRSAFE_LPWSTR pszDest,size_t cbDest);
741
742 #define StringCbGets __MINGW_NAME_AW(StringCbGets)
743
744 #ifndef __CRT__NO_INLINE
StringCbGetsA(STRSAFE_LPSTR pszDest,size_t cbDest)745 STRSAFE_INLINE_API StringCbGetsA(STRSAFE_LPSTR pszDest,size_t cbDest) {
746 HRESULT hr;
747 size_t cchDest;
748 cchDest = cbDest / sizeof(char);
749 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
750 else hr = StringGetsExWorkerA(pszDest,cchDest,cbDest,NULL,NULL,0);
751 return hr;
752 }
753
StringCbGetsW(STRSAFE_LPWSTR pszDest,size_t cbDest)754 STRSAFE_INLINE_API StringCbGetsW(STRSAFE_LPWSTR pszDest,size_t cbDest) {
755 HRESULT hr;
756 size_t cchDest;
757 cchDest = cbDest / sizeof(wchar_t);
758 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
759 else hr = StringGetsExWorkerW(pszDest,cchDest,cbDest,NULL,NULL,0);
760 return hr;
761 }
762 #endif /* !__CRT__NO_INLINE */
763
764 STRSAFE_INLINE_API StringCchGetsExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
765 STRSAFE_INLINE_API StringCchGetsExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags);
766
767 #define StringCchGetsEx __MINGW_NAME_AW(StringCchGetsEx)
768
769 #ifndef __CRT__NO_INLINE
StringCchGetsExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)770 STRSAFE_INLINE_API StringCchGetsExA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
771 HRESULT hr;
772 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
773 else {
774 size_t cbDest;
775 cbDest = cchDest*sizeof(char);
776 hr = StringGetsExWorkerA(pszDest,cchDest,cbDest,ppszDestEnd,pcchRemaining,dwFlags);
777 }
778 return hr;
779 }
780
StringCchGetsExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)781 STRSAFE_INLINE_API StringCchGetsExW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
782 HRESULT hr;
783 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
784 else {
785 size_t cbDest;
786 cbDest = cchDest*sizeof(wchar_t);
787 hr = StringGetsExWorkerW(pszDest,cchDest,cbDest,ppszDestEnd,pcchRemaining,dwFlags);
788 }
789 return hr;
790 }
791 #endif /* !__CRT__NO_INLINE */
792
793 STRSAFE_INLINE_API StringCbGetsExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags);
794 STRSAFE_INLINE_API StringCbGetsExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags);
795
796 #define StringCbGetsEx __MINGW_NAME_AW(StringCbGetsEx)
797
798 #ifndef __CRT__NO_INLINE
StringCbGetsExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPSTR * ppszDestEnd,size_t * pcbRemaining,STRSAFE_DWORD dwFlags)799 STRSAFE_INLINE_API StringCbGetsExA(STRSAFE_LPSTR pszDest,size_t cbDest,STRSAFE_LPSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags) {
800 HRESULT hr;
801 size_t cchDest;
802 size_t cchRemaining = 0;
803 cchDest = cbDest / sizeof(char);
804 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
805 else hr = StringGetsExWorkerA(pszDest,cchDest,cbDest,ppszDestEnd,&cchRemaining,dwFlags);
806 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER) || (hr==STRSAFE_E_END_OF_FILE)) {
807 if(pcbRemaining) *pcbRemaining = (cchRemaining*sizeof(char)) + (cbDest % sizeof(char));
808 }
809 return hr;
810 }
811
StringCbGetsExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcbRemaining,STRSAFE_DWORD dwFlags)812 STRSAFE_INLINE_API StringCbGetsExW(STRSAFE_LPWSTR pszDest,size_t cbDest,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcbRemaining,STRSAFE_DWORD dwFlags) {
813 HRESULT hr;
814 size_t cchDest;
815 size_t cchRemaining = 0;
816 cchDest = cbDest / sizeof(wchar_t);
817 if(cchDest > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
818 else hr = StringGetsExWorkerW(pszDest,cchDest,cbDest,ppszDestEnd,&cchRemaining,dwFlags);
819 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER) || (hr==STRSAFE_E_END_OF_FILE)) {
820 if(pcbRemaining) *pcbRemaining = (cchRemaining*sizeof(wchar_t)) + (cbDest % sizeof(wchar_t));
821 }
822 return hr;
823 }
824 #endif /* !__CRT__NO_INLINE */
825
826 STRSAFEAPI StringCchLengthA(STRSAFE_LPCSTR psz,size_t cchMax,size_t *pcchLength);
827 STRSAFEAPI StringCchLengthW(STRSAFE_LPCWSTR psz,size_t cchMax,size_t *pcchLength);
828
829 #define StringCchLength __MINGW_NAME_AW(StringCchLength)
830
831 #ifndef __CRT__NO_INLINE
StringCchLengthA(STRSAFE_LPCSTR psz,size_t cchMax,size_t * pcchLength)832 STRSAFEAPI StringCchLengthA(STRSAFE_LPCSTR psz,size_t cchMax,size_t *pcchLength) {
833 HRESULT hr;
834 if(!psz || (cchMax > STRSAFE_MAX_CCH)) hr = STRSAFE_E_INVALID_PARAMETER;
835 else hr = StringLengthWorkerA(psz,cchMax,pcchLength);
836 if(FAILED(hr) && pcchLength) {
837 *pcchLength = 0;
838 }
839 return hr;
840 }
841
StringCchLengthW(STRSAFE_LPCWSTR psz,size_t cchMax,size_t * pcchLength)842 STRSAFEAPI StringCchLengthW(STRSAFE_LPCWSTR psz,size_t cchMax,size_t *pcchLength) {
843 HRESULT hr;
844 if(!psz || (cchMax > STRSAFE_MAX_CCH)) hr = STRSAFE_E_INVALID_PARAMETER;
845 else hr = StringLengthWorkerW(psz,cchMax,pcchLength);
846 if(FAILED(hr) && pcchLength) {
847 *pcchLength = 0;
848 }
849 return hr;
850 }
851 #endif /* !__CRT__NO_INLINE */
852
853 STRSAFEAPI StringCbLengthA(STRSAFE_LPCSTR psz,size_t cbMax,size_t *pcbLength);
854 STRSAFEAPI StringCbLengthW(STRSAFE_LPCWSTR psz,size_t cbMax,size_t *pcbLength);
855
856 #define StringCbLength __MINGW_NAME_AW(StringCbLength)
857
858 #ifndef __CRT__NO_INLINE
StringCbLengthA(STRSAFE_LPCSTR psz,size_t cbMax,size_t * pcbLength)859 STRSAFEAPI StringCbLengthA(STRSAFE_LPCSTR psz,size_t cbMax,size_t *pcbLength) {
860 HRESULT hr;
861 size_t cchMax;
862 size_t cchLength = 0;
863 cchMax = cbMax / sizeof(char);
864 if(!psz || (cchMax > STRSAFE_MAX_CCH)) hr = STRSAFE_E_INVALID_PARAMETER;
865 else hr = StringLengthWorkerA(psz,cchMax,&cchLength);
866 if(pcbLength) {
867 if(SUCCEEDED(hr)) {
868 *pcbLength = cchLength*sizeof(char);
869 } else {
870 *pcbLength = 0;
871 }
872 }
873 return hr;
874 }
875
StringCbLengthW(STRSAFE_LPCWSTR psz,size_t cbMax,size_t * pcbLength)876 STRSAFEAPI StringCbLengthW(STRSAFE_LPCWSTR psz,size_t cbMax,size_t *pcbLength) {
877 HRESULT hr;
878 size_t cchMax;
879 size_t cchLength = 0;
880 cchMax = cbMax / sizeof(wchar_t);
881 if(!psz || (cchMax > STRSAFE_MAX_CCH)) hr = STRSAFE_E_INVALID_PARAMETER;
882 else hr = StringLengthWorkerW(psz,cchMax,&cchLength);
883 if(pcbLength) {
884 if(SUCCEEDED(hr)) {
885 *pcbLength = cchLength*sizeof(wchar_t);
886 } else {
887 *pcbLength = 0;
888 }
889 }
890 return hr;
891 }
892
StringCopyWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc)893 STRSAFEAPI StringCopyWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc) {
894 HRESULT hr = S_OK;
895 if(cchDest==0) hr = STRSAFE_E_INVALID_PARAMETER;
896 else {
897 while(cchDest && (*pszSrc!='\0')) {
898 *pszDest++ = *pszSrc++;
899 cchDest--;
900 }
901 if(cchDest==0) {
902 pszDest--;
903 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
904 }
905 *pszDest= '\0';
906 }
907 return hr;
908 }
909
StringCopyWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc)910 STRSAFEAPI StringCopyWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc) {
911 HRESULT hr = S_OK;
912 if(cchDest==0) hr = STRSAFE_E_INVALID_PARAMETER;
913 else {
914 while(cchDest && (*pszSrc!=L'\0')) {
915 *pszDest++ = *pszSrc++;
916 cchDest--;
917 }
918 if(cchDest==0) {
919 pszDest--;
920 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
921 }
922 *pszDest= L'\0';
923 }
924 return hr;
925 }
926
StringCopyExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)927 STRSAFEAPI StringCopyExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
928 HRESULT hr = S_OK;
929 STRSAFE_LPSTR pszDestEnd = pszDest;
930 size_t cchRemaining = 0;
931 if(dwFlags & (~STRSAFE_VALID_FLAGS)) hr = STRSAFE_E_INVALID_PARAMETER;
932 else {
933 if(dwFlags & STRSAFE_IGNORE_NULLS) {
934 if(!pszDest) {
935 if((cchDest!=0) || (cbDest!=0)) hr = STRSAFE_E_INVALID_PARAMETER;
936 }
937 if(!pszSrc) pszSrc = "";
938 }
939 if(SUCCEEDED(hr)) {
940 if(cchDest==0) {
941 pszDestEnd = pszDest;
942 cchRemaining = 0;
943 if(*pszSrc!='\0') {
944 if(!pszDest) hr = STRSAFE_E_INVALID_PARAMETER;
945 else hr = STRSAFE_E_INSUFFICIENT_BUFFER;
946 }
947 } else {
948 pszDestEnd = pszDest;
949 cchRemaining = cchDest;
950 while(cchRemaining && (*pszSrc!='\0')) {
951 *pszDestEnd++ = *pszSrc++;
952 cchRemaining--;
953 }
954 if(cchRemaining > 0) {
955 if(dwFlags & STRSAFE_FILL_BEHIND_NULL) {
956 memset(pszDestEnd + 1,STRSAFE_GET_FILL_PATTERN(dwFlags),((cchRemaining - 1)*sizeof(char)) + (cbDest % sizeof(char)));
957 }
958 } else {
959 pszDestEnd--;
960 cchRemaining++;
961 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
962 }
963 *pszDestEnd = '\0';
964 }
965 }
966 }
967 if(FAILED(hr)) {
968 if(pszDest) {
969 if(dwFlags & STRSAFE_FILL_ON_FAILURE) {
970 memset(pszDest,STRSAFE_GET_FILL_PATTERN(dwFlags),cbDest);
971 if(STRSAFE_GET_FILL_PATTERN(dwFlags)==0) {
972 pszDestEnd = pszDest;
973 cchRemaining = cchDest;
974 } else if(cchDest > 0) {
975 pszDestEnd = pszDest + cchDest - 1;
976 cchRemaining = 1;
977 *pszDestEnd = '\0';
978 }
979 }
980 if(dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) {
981 if(cchDest > 0) {
982 pszDestEnd = pszDest;
983 cchRemaining = cchDest;
984 *pszDestEnd = '\0';
985 }
986 }
987 }
988 }
989 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER)) {
990 if(ppszDestEnd) *ppszDestEnd = pszDestEnd;
991 if(pcchRemaining) *pcchRemaining = cchRemaining;
992 }
993 return hr;
994 }
995
StringCopyExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)996 STRSAFEAPI StringCopyExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
997 HRESULT hr = S_OK;
998 STRSAFE_LPWSTR pszDestEnd = pszDest;
999 size_t cchRemaining = 0;
1000 if(dwFlags & (~STRSAFE_VALID_FLAGS)) hr = STRSAFE_E_INVALID_PARAMETER;
1001 else {
1002 if(dwFlags & STRSAFE_IGNORE_NULLS) {
1003 if(!pszDest) {
1004 if((cchDest!=0) || (cbDest!=0)) hr = STRSAFE_E_INVALID_PARAMETER;
1005 }
1006 if(!pszSrc) pszSrc = L"";
1007 }
1008 if(SUCCEEDED(hr)) {
1009 if(cchDest==0) {
1010 pszDestEnd = pszDest;
1011 cchRemaining = 0;
1012 if(*pszSrc!=L'\0') {
1013 if(!pszDest) hr = STRSAFE_E_INVALID_PARAMETER;
1014 else hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1015 }
1016 } else {
1017 pszDestEnd = pszDest;
1018 cchRemaining = cchDest;
1019 while(cchRemaining && (*pszSrc!=L'\0')) {
1020 *pszDestEnd++ = *pszSrc++;
1021 cchRemaining--;
1022 }
1023 if(cchRemaining > 0) {
1024 if(dwFlags & STRSAFE_FILL_BEHIND_NULL) {
1025 memset(pszDestEnd + 1,STRSAFE_GET_FILL_PATTERN(dwFlags),((cchRemaining - 1)*sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)));
1026 }
1027 } else {
1028 pszDestEnd--;
1029 cchRemaining++;
1030 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1031 }
1032 *pszDestEnd = L'\0';
1033 }
1034 }
1035 }
1036 if(FAILED(hr)) {
1037 if(pszDest) {
1038 if(dwFlags & STRSAFE_FILL_ON_FAILURE) {
1039 memset(pszDest,STRSAFE_GET_FILL_PATTERN(dwFlags),cbDest);
1040 if(STRSAFE_GET_FILL_PATTERN(dwFlags)==0) {
1041 pszDestEnd = pszDest;
1042 cchRemaining = cchDest;
1043 } else if(cchDest > 0) {
1044 pszDestEnd = pszDest + cchDest - 1;
1045 cchRemaining = 1;
1046 *pszDestEnd = L'\0';
1047 }
1048 }
1049 if(dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) {
1050 if(cchDest > 0) {
1051 pszDestEnd = pszDest;
1052 cchRemaining = cchDest;
1053 *pszDestEnd = L'\0';
1054 }
1055 }
1056 }
1057 }
1058 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER)) {
1059 if(ppszDestEnd) *ppszDestEnd = pszDestEnd;
1060 if(pcchRemaining) *pcchRemaining = cchRemaining;
1061 }
1062 return hr;
1063 }
1064
StringCopyNWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchSrc)1065 STRSAFEAPI StringCopyNWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchSrc) {
1066 HRESULT hr = S_OK;
1067 if(cchDest==0) hr = STRSAFE_E_INVALID_PARAMETER;
1068 else {
1069 while(cchDest && cchSrc && (*pszSrc!='\0')) {
1070 *pszDest++ = *pszSrc++;
1071 cchDest--;
1072 cchSrc--;
1073 }
1074 if(cchDest==0) {
1075 pszDest--;
1076 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1077 }
1078 *pszDest= '\0';
1079 }
1080 return hr;
1081 }
1082
StringCopyNWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToCopy)1083 STRSAFEAPI StringCopyNWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToCopy) {
1084 HRESULT hr = S_OK;
1085 if(cchDest==0) hr = STRSAFE_E_INVALID_PARAMETER;
1086 else {
1087 while(cchDest && cchToCopy && (*pszSrc!=L'\0')) {
1088 *pszDest++ = *pszSrc++;
1089 cchDest--;
1090 cchToCopy--;
1091 }
1092 if(cchDest==0) {
1093 pszDest--;
1094 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1095 }
1096 *pszDest= L'\0';
1097 }
1098 return hr;
1099 }
1100
StringCopyNExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cchToCopy,STRSAFE_LPSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)1101 STRSAFEAPI StringCopyNExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cchToCopy,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
1102 HRESULT hr = S_OK;
1103 STRSAFE_LPSTR pszDestEnd = pszDest;
1104 size_t cchRemaining = 0;
1105 if(dwFlags & (~STRSAFE_VALID_FLAGS)) hr = STRSAFE_E_INVALID_PARAMETER;
1106 else if(cchToCopy > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
1107 else {
1108 if(dwFlags & STRSAFE_IGNORE_NULLS) {
1109 if(!pszDest) {
1110 if((cchDest!=0) || (cbDest!=0)) hr = STRSAFE_E_INVALID_PARAMETER;
1111 }
1112 if(!pszSrc) pszSrc = "";
1113 }
1114 if(SUCCEEDED(hr)) {
1115 if(cchDest==0) {
1116 pszDestEnd = pszDest;
1117 cchRemaining = 0;
1118 if((cchToCopy!=0) && (*pszSrc!='\0')) {
1119 if(!pszDest) hr = STRSAFE_E_INVALID_PARAMETER;
1120 else hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1121 }
1122 } else {
1123 pszDestEnd = pszDest;
1124 cchRemaining = cchDest;
1125 while(cchRemaining && cchToCopy && (*pszSrc!='\0')) {
1126 *pszDestEnd++ = *pszSrc++;
1127 cchRemaining--;
1128 cchToCopy--;
1129 }
1130 if(cchRemaining > 0) {
1131 if(dwFlags & STRSAFE_FILL_BEHIND_NULL) {
1132 memset(pszDestEnd + 1,STRSAFE_GET_FILL_PATTERN(dwFlags),((cchRemaining - 1)*sizeof(char)) + (cbDest % sizeof(char)));
1133 }
1134 } else {
1135 pszDestEnd--;
1136 cchRemaining++;
1137 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1138 }
1139 *pszDestEnd = '\0';
1140 }
1141 }
1142 }
1143 if(FAILED(hr)) {
1144 if(pszDest) {
1145 if(dwFlags & STRSAFE_FILL_ON_FAILURE) {
1146 memset(pszDest,STRSAFE_GET_FILL_PATTERN(dwFlags),cbDest);
1147 if(STRSAFE_GET_FILL_PATTERN(dwFlags)==0) {
1148 pszDestEnd = pszDest;
1149 cchRemaining = cchDest;
1150 } else if(cchDest > 0) {
1151 pszDestEnd = pszDest + cchDest - 1;
1152 cchRemaining = 1;
1153 *pszDestEnd = '\0';
1154 }
1155 }
1156 if(dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) {
1157 if(cchDest > 0) {
1158 pszDestEnd = pszDest;
1159 cchRemaining = cchDest;
1160 *pszDestEnd = '\0';
1161 }
1162 }
1163 }
1164 }
1165 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER)) {
1166 if(ppszDestEnd) *ppszDestEnd = pszDestEnd;
1167 if(pcchRemaining) *pcchRemaining = cchRemaining;
1168 }
1169 return hr;
1170 }
1171
StringCopyNExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cchToCopy,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)1172 STRSAFEAPI StringCopyNExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cchToCopy,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
1173 HRESULT hr = S_OK;
1174 STRSAFE_LPWSTR pszDestEnd = pszDest;
1175 size_t cchRemaining = 0;
1176 if(dwFlags & (~STRSAFE_VALID_FLAGS)) hr = STRSAFE_E_INVALID_PARAMETER;
1177 else if(cchToCopy > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
1178 else {
1179 if(dwFlags & STRSAFE_IGNORE_NULLS) {
1180 if(!pszDest) {
1181 if((cchDest!=0) || (cbDest!=0)) hr = STRSAFE_E_INVALID_PARAMETER;
1182 }
1183 if(!pszSrc) pszSrc = L"";
1184 }
1185 if(SUCCEEDED(hr)) {
1186 if(cchDest==0) {
1187 pszDestEnd = pszDest;
1188 cchRemaining = 0;
1189 if((cchToCopy!=0) && (*pszSrc!=L'\0')) {
1190 if(!pszDest) hr = STRSAFE_E_INVALID_PARAMETER;
1191 else hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1192 }
1193 } else {
1194 pszDestEnd = pszDest;
1195 cchRemaining = cchDest;
1196 while(cchRemaining && cchToCopy && (*pszSrc!=L'\0')) {
1197 *pszDestEnd++ = *pszSrc++;
1198 cchRemaining--;
1199 cchToCopy--;
1200 }
1201 if(cchRemaining > 0) {
1202 if(dwFlags & STRSAFE_FILL_BEHIND_NULL) {
1203 memset(pszDestEnd + 1,STRSAFE_GET_FILL_PATTERN(dwFlags),((cchRemaining - 1)*sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)));
1204 }
1205 } else {
1206 pszDestEnd--;
1207 cchRemaining++;
1208 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1209 }
1210 *pszDestEnd = L'\0';
1211 }
1212 }
1213 }
1214 if(FAILED(hr)) {
1215 if(pszDest) {
1216 if(dwFlags & STRSAFE_FILL_ON_FAILURE) {
1217 memset(pszDest,STRSAFE_GET_FILL_PATTERN(dwFlags),cbDest);
1218 if(STRSAFE_GET_FILL_PATTERN(dwFlags)==0) {
1219 pszDestEnd = pszDest;
1220 cchRemaining = cchDest;
1221 } else if(cchDest > 0) {
1222 pszDestEnd = pszDest + cchDest - 1;
1223 cchRemaining = 1;
1224 *pszDestEnd = L'\0';
1225 }
1226 }
1227 if(dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) {
1228 if(cchDest > 0) {
1229 pszDestEnd = pszDest;
1230 cchRemaining = cchDest;
1231 *pszDestEnd = L'\0';
1232 }
1233 }
1234 }
1235 }
1236 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER)) {
1237 if(ppszDestEnd) *ppszDestEnd = pszDestEnd;
1238 if(pcchRemaining) *pcchRemaining = cchRemaining;
1239 }
1240 return hr;
1241 }
1242
StringCatWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc)1243 STRSAFEAPI StringCatWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc) {
1244 HRESULT hr;
1245 size_t cchDestLength;
1246 hr = StringLengthWorkerA(pszDest,cchDest,&cchDestLength);
1247 if(SUCCEEDED(hr)) hr = StringCopyWorkerA(pszDest + cchDestLength,cchDest - cchDestLength,pszSrc);
1248 return hr;
1249 }
1250
StringCatWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc)1251 STRSAFEAPI StringCatWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc) {
1252 HRESULT hr;
1253 size_t cchDestLength;
1254 hr = StringLengthWorkerW(pszDest,cchDest,&cchDestLength);
1255 if(SUCCEEDED(hr)) hr = StringCopyWorkerW(pszDest + cchDestLength,cchDest - cchDestLength,pszSrc);
1256 return hr;
1257 }
1258
StringCatExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)1259 STRSAFEAPI StringCatExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
1260 HRESULT hr = S_OK;
1261 STRSAFE_LPSTR pszDestEnd = pszDest;
1262 size_t cchRemaining = 0;
1263 if(dwFlags & (~STRSAFE_VALID_FLAGS)) hr = STRSAFE_E_INVALID_PARAMETER;
1264 else {
1265 size_t cchDestLength;
1266 if(dwFlags & STRSAFE_IGNORE_NULLS) {
1267 if(!pszDest) {
1268 if((cchDest==0) && (cbDest==0)) cchDestLength = 0;
1269 else hr = STRSAFE_E_INVALID_PARAMETER;
1270 } else {
1271 hr = StringLengthWorkerA(pszDest,cchDest,&cchDestLength);
1272 if(SUCCEEDED(hr)) {
1273 pszDestEnd = pszDest + cchDestLength;
1274 cchRemaining = cchDest - cchDestLength;
1275 }
1276 }
1277 if(!pszSrc) pszSrc = "";
1278 } else {
1279 hr = StringLengthWorkerA(pszDest,cchDest,&cchDestLength);
1280 if(SUCCEEDED(hr)) {
1281 pszDestEnd = pszDest + cchDestLength;
1282 cchRemaining = cchDest - cchDestLength;
1283 }
1284 }
1285 if(SUCCEEDED(hr)) {
1286 if(cchDest==0) {
1287 if(*pszSrc!='\0') {
1288 if(!pszDest) hr = STRSAFE_E_INVALID_PARAMETER;
1289 else hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1290 }
1291 } else hr = StringCopyExWorkerA(pszDestEnd,cchRemaining,(cchRemaining*sizeof(char)) + (cbDest % sizeof(char)),pszSrc,&pszDestEnd,&cchRemaining,dwFlags & (~(STRSAFE_FILL_ON_FAILURE | STRSAFE_NULL_ON_FAILURE)));
1292 }
1293 }
1294 if(FAILED(hr)) {
1295 if(pszDest) {
1296 if(dwFlags & STRSAFE_FILL_ON_FAILURE) {
1297 memset(pszDest,STRSAFE_GET_FILL_PATTERN(dwFlags),cbDest);
1298 if(STRSAFE_GET_FILL_PATTERN(dwFlags)==0) {
1299 pszDestEnd = pszDest;
1300 cchRemaining = cchDest;
1301 } else if(cchDest > 0) {
1302 pszDestEnd = pszDest + cchDest - 1;
1303 cchRemaining = 1;
1304 *pszDestEnd = '\0';
1305 }
1306 }
1307 if(dwFlags & STRSAFE_NULL_ON_FAILURE) {
1308 if(cchDest > 0) {
1309 pszDestEnd = pszDest;
1310 cchRemaining = cchDest;
1311 *pszDestEnd = '\0';
1312 }
1313 }
1314 }
1315 }
1316 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER)) {
1317 if(ppszDestEnd) *ppszDestEnd = pszDestEnd;
1318 if(pcchRemaining) *pcchRemaining = cchRemaining;
1319 }
1320 return hr;
1321 }
1322
StringCatExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)1323 STRSAFEAPI StringCatExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
1324 HRESULT hr = S_OK;
1325 STRSAFE_LPWSTR pszDestEnd = pszDest;
1326 size_t cchRemaining = 0;
1327 if(dwFlags & (~STRSAFE_VALID_FLAGS)) hr = STRSAFE_E_INVALID_PARAMETER;
1328 else {
1329 size_t cchDestLength;
1330 if(dwFlags & STRSAFE_IGNORE_NULLS) {
1331 if(!pszDest) {
1332 if((cchDest==0) && (cbDest==0)) cchDestLength = 0;
1333 else hr = STRSAFE_E_INVALID_PARAMETER;
1334 } else {
1335 hr = StringLengthWorkerW(pszDest,cchDest,&cchDestLength);
1336 if(SUCCEEDED(hr)) {
1337 pszDestEnd = pszDest + cchDestLength;
1338 cchRemaining = cchDest - cchDestLength;
1339 }
1340 }
1341 if(!pszSrc) pszSrc = L"";
1342 } else {
1343 hr = StringLengthWorkerW(pszDest,cchDest,&cchDestLength);
1344 if(SUCCEEDED(hr)) {
1345 pszDestEnd = pszDest + cchDestLength;
1346 cchRemaining = cchDest - cchDestLength;
1347 }
1348 }
1349 if(SUCCEEDED(hr)) {
1350 if(cchDest==0) {
1351 if(*pszSrc!=L'\0') {
1352 if(!pszDest) hr = STRSAFE_E_INVALID_PARAMETER;
1353 else hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1354 }
1355 } else hr = StringCopyExWorkerW(pszDestEnd,cchRemaining,(cchRemaining*sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)),pszSrc,&pszDestEnd,&cchRemaining,dwFlags & (~(STRSAFE_FILL_ON_FAILURE | STRSAFE_NULL_ON_FAILURE)));
1356 }
1357 }
1358 if(FAILED(hr)) {
1359 if(pszDest) {
1360 if(dwFlags & STRSAFE_FILL_ON_FAILURE) {
1361 memset(pszDest,STRSAFE_GET_FILL_PATTERN(dwFlags),cbDest);
1362 if(STRSAFE_GET_FILL_PATTERN(dwFlags)==0) {
1363 pszDestEnd = pszDest;
1364 cchRemaining = cchDest;
1365 } else if(cchDest > 0) {
1366 pszDestEnd = pszDest + cchDest - 1;
1367 cchRemaining = 1;
1368 *pszDestEnd = L'\0';
1369 }
1370 }
1371 if(dwFlags & STRSAFE_NULL_ON_FAILURE) {
1372 if(cchDest > 0) {
1373 pszDestEnd = pszDest;
1374 cchRemaining = cchDest;
1375 *pszDestEnd = L'\0';
1376 }
1377 }
1378 }
1379 }
1380 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER)) {
1381 if(ppszDestEnd) *ppszDestEnd = pszDestEnd;
1382 if(pcchRemaining) *pcchRemaining = cchRemaining;
1383 }
1384 return hr;
1385 }
1386
StringCatNWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend)1387 STRSAFEAPI StringCatNWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend) {
1388 HRESULT hr;
1389 size_t cchDestLength;
1390 hr = StringLengthWorkerA(pszDest,cchDest,&cchDestLength);
1391 if(SUCCEEDED(hr)) hr = StringCopyNWorkerA(pszDest + cchDestLength,cchDest - cchDestLength,pszSrc,cchToAppend);
1392 return hr;
1393 }
1394
StringCatNWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToAppend)1395 STRSAFEAPI StringCatNWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszSrc,size_t cchToAppend) {
1396 HRESULT hr;
1397 size_t cchDestLength;
1398 hr = StringLengthWorkerW(pszDest,cchDest,&cchDestLength);
1399 if(SUCCEEDED(hr)) hr = StringCopyNWorkerW(pszDest + cchDestLength,cchDest - cchDestLength,pszSrc,cchToAppend);
1400 return hr;
1401 }
1402
StringCatNExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend,STRSAFE_LPSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)1403 STRSAFEAPI StringCatNExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCSTR pszSrc,size_t cchToAppend,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
1404 HRESULT hr = S_OK;
1405 STRSAFE_LPSTR pszDestEnd = pszDest;
1406 size_t cchRemaining = 0;
1407 size_t cchDestLength = 0;
1408 if(dwFlags & (~STRSAFE_VALID_FLAGS)) hr = STRSAFE_E_INVALID_PARAMETER;
1409 else if(cchToAppend > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
1410 else {
1411 if(dwFlags & STRSAFE_IGNORE_NULLS) {
1412 if(!pszDest) {
1413 if((cchDest==0) && (cbDest==0)) cchDestLength = 0;
1414 else hr = STRSAFE_E_INVALID_PARAMETER;
1415 } else {
1416 hr = StringLengthWorkerA(pszDest,cchDest,&cchDestLength);
1417 if(SUCCEEDED(hr)) {
1418 pszDestEnd = pszDest + cchDestLength;
1419 cchRemaining = cchDest - cchDestLength;
1420 }
1421 }
1422 if(!pszSrc) pszSrc = "";
1423 } else {
1424 hr = StringLengthWorkerA(pszDest,cchDest,&cchDestLength);
1425 if(SUCCEEDED(hr)) {
1426 pszDestEnd = pszDest + cchDestLength;
1427 cchRemaining = cchDest - cchDestLength;
1428 }
1429 }
1430 if(SUCCEEDED(hr)) {
1431 if(cchDest==0) {
1432 if((cchToAppend!=0) && (*pszSrc!='\0')) {
1433 if(!pszDest) hr = STRSAFE_E_INVALID_PARAMETER;
1434 else hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1435 }
1436 } else hr = StringCopyNExWorkerA(pszDestEnd,cchRemaining,(cchRemaining*sizeof(char)) + (cbDest % sizeof(char)),pszSrc,cchToAppend,&pszDestEnd,&cchRemaining,dwFlags & (~(STRSAFE_FILL_ON_FAILURE | STRSAFE_NULL_ON_FAILURE)));
1437 }
1438 }
1439 if(FAILED(hr)) {
1440 if(pszDest) {
1441 if(dwFlags & STRSAFE_FILL_ON_FAILURE) {
1442 memset(pszDest,STRSAFE_GET_FILL_PATTERN(dwFlags),cbDest);
1443 if(STRSAFE_GET_FILL_PATTERN(dwFlags)==0) {
1444 pszDestEnd = pszDest;
1445 cchRemaining = cchDest;
1446 } else if(cchDest > 0) {
1447 pszDestEnd = pszDest + cchDest - 1;
1448 cchRemaining = 1;
1449 *pszDestEnd = '\0';
1450 }
1451 }
1452 if(dwFlags & (STRSAFE_NULL_ON_FAILURE)) {
1453 if(cchDest > 0) {
1454 pszDestEnd = pszDest;
1455 cchRemaining = cchDest;
1456 *pszDestEnd = '\0';
1457 }
1458 }
1459 }
1460 }
1461 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER)) {
1462 if(ppszDestEnd) *ppszDestEnd = pszDestEnd;
1463 if(pcchRemaining) *pcchRemaining = cchRemaining;
1464 }
1465 return hr;
1466 }
1467
StringCatNExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cchToAppend,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)1468 STRSAFEAPI StringCatNExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPCWSTR pszSrc,size_t cchToAppend,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
1469 HRESULT hr = S_OK;
1470 STRSAFE_LPWSTR pszDestEnd = pszDest;
1471 size_t cchRemaining = 0;
1472 size_t cchDestLength = 0;
1473 if(dwFlags & (~STRSAFE_VALID_FLAGS)) hr = STRSAFE_E_INVALID_PARAMETER;
1474 else if(cchToAppend > STRSAFE_MAX_CCH) hr = STRSAFE_E_INVALID_PARAMETER;
1475 else {
1476 if(dwFlags & STRSAFE_IGNORE_NULLS) {
1477 if(!pszDest) {
1478 if((cchDest==0) && (cbDest==0)) cchDestLength = 0;
1479 else hr = STRSAFE_E_INVALID_PARAMETER;
1480 } else {
1481 hr = StringLengthWorkerW(pszDest,cchDest,&cchDestLength);
1482 if(SUCCEEDED(hr)) {
1483 pszDestEnd = pszDest + cchDestLength;
1484 cchRemaining = cchDest - cchDestLength;
1485 }
1486 }
1487 if(!pszSrc) pszSrc = L"";
1488 } else {
1489 hr = StringLengthWorkerW(pszDest,cchDest,&cchDestLength);
1490 if(SUCCEEDED(hr)) {
1491 pszDestEnd = pszDest + cchDestLength;
1492 cchRemaining = cchDest - cchDestLength;
1493 }
1494 }
1495 if(SUCCEEDED(hr)) {
1496 if(cchDest==0) {
1497 if((cchToAppend!=0) && (*pszSrc!=L'\0')) {
1498 if(!pszDest) hr = STRSAFE_E_INVALID_PARAMETER;
1499 else hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1500 }
1501 } else hr = StringCopyNExWorkerW(pszDestEnd,cchRemaining,(cchRemaining*sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)),pszSrc,cchToAppend,&pszDestEnd,&cchRemaining,dwFlags & (~(STRSAFE_FILL_ON_FAILURE | STRSAFE_NULL_ON_FAILURE)));
1502 }
1503 }
1504 if(FAILED(hr)) {
1505 if(pszDest) {
1506 if(dwFlags & STRSAFE_FILL_ON_FAILURE) {
1507 memset(pszDest,STRSAFE_GET_FILL_PATTERN(dwFlags),cbDest);
1508 if(STRSAFE_GET_FILL_PATTERN(dwFlags)==0) {
1509 pszDestEnd = pszDest;
1510 cchRemaining = cchDest;
1511 } else if(cchDest > 0) {
1512 pszDestEnd = pszDest + cchDest - 1;
1513 cchRemaining = 1;
1514 *pszDestEnd = L'\0';
1515 }
1516 }
1517 if(dwFlags & (STRSAFE_NULL_ON_FAILURE)) {
1518 if(cchDest > 0) {
1519 pszDestEnd = pszDest;
1520 cchRemaining = cchDest;
1521 *pszDestEnd = L'\0';
1522 }
1523 }
1524 }
1525 }
1526 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER)) {
1527 if(ppszDestEnd) *ppszDestEnd = pszDestEnd;
1528 if(pcchRemaining) *pcchRemaining = cchRemaining;
1529 }
1530 return hr;
1531 }
1532
StringVPrintfWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszFormat,va_list argList)1533 STRSAFEAPI StringVPrintfWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,STRSAFE_LPCSTR pszFormat,va_list argList) {
1534 HRESULT hr = S_OK;
1535 if(cchDest==0) hr = STRSAFE_E_INVALID_PARAMETER;
1536 else {
1537 int iRet;
1538 size_t cchMax;
1539 cchMax = cchDest - 1;
1540 iRet = _vsnprintf(pszDest,cchMax,pszFormat,argList);
1541 if((iRet < 0) || (((size_t)iRet) > cchMax)) {
1542 pszDest += cchMax;
1543 *pszDest = '\0';
1544 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1545 } else if(((size_t)iRet)==cchMax) {
1546 pszDest += cchMax;
1547 *pszDest = '\0';
1548 }
1549 }
1550 return hr;
1551 }
1552
StringVPrintfWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszFormat,va_list argList)1553 STRSAFEAPI StringVPrintfWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,STRSAFE_LPCWSTR pszFormat,va_list argList) {
1554 HRESULT hr = S_OK;
1555 if(cchDest==0) hr = STRSAFE_E_INVALID_PARAMETER;
1556 else {
1557 int iRet;
1558 size_t cchMax;
1559 cchMax = cchDest - 1;
1560 iRet = _vsnwprintf(pszDest,cchMax,pszFormat,argList);
1561 if((iRet < 0) || (((size_t)iRet) > cchMax)) {
1562 pszDest += cchMax;
1563 *pszDest = L'\0';
1564 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1565 } else if(((size_t)iRet)==cchMax) {
1566 pszDest += cchMax;
1567 *pszDest = L'\0';
1568 }
1569 }
1570 return hr;
1571 }
1572
StringVPrintfExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCSTR pszFormat,va_list argList)1573 STRSAFEAPI StringVPrintfExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCSTR pszFormat,va_list argList) {
1574 HRESULT hr = S_OK;
1575 STRSAFE_LPSTR pszDestEnd = pszDest;
1576 size_t cchRemaining = 0;
1577 if(dwFlags & (~STRSAFE_VALID_FLAGS)) hr = STRSAFE_E_INVALID_PARAMETER;
1578 else {
1579 if(dwFlags & STRSAFE_IGNORE_NULLS) {
1580 if(!pszDest) {
1581 if((cchDest!=0) || (cbDest!=0)) hr = STRSAFE_E_INVALID_PARAMETER;
1582 }
1583 if(!pszFormat) pszFormat = "";
1584 }
1585 if(SUCCEEDED(hr)) {
1586 if(cchDest==0) {
1587 pszDestEnd = pszDest;
1588 cchRemaining = 0;
1589 if(*pszFormat!='\0') {
1590 if(!pszDest) hr = STRSAFE_E_INVALID_PARAMETER;
1591 else hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1592 }
1593 } else {
1594 int iRet;
1595 size_t cchMax;
1596 cchMax = cchDest - 1;
1597 iRet = _vsnprintf(pszDest,cchMax,pszFormat,argList);
1598 if((iRet < 0) || (((size_t)iRet) > cchMax)) {
1599 pszDestEnd = pszDest + cchMax;
1600 cchRemaining = 1;
1601 *pszDestEnd = '\0';
1602 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1603 } else if(((size_t)iRet)==cchMax) {
1604 pszDestEnd = pszDest + cchMax;
1605 cchRemaining = 1;
1606 *pszDestEnd = '\0';
1607 } else if(((size_t)iRet) < cchMax) {
1608 pszDestEnd = pszDest + iRet;
1609 cchRemaining = cchDest - iRet;
1610 if(dwFlags & STRSAFE_FILL_BEHIND_NULL) {
1611 memset(pszDestEnd + 1,STRSAFE_GET_FILL_PATTERN(dwFlags),((cchRemaining - 1)*sizeof(char)) + (cbDest % sizeof(char)));
1612 }
1613 }
1614 }
1615 }
1616 }
1617 if(FAILED(hr)) {
1618 if(pszDest) {
1619 if(dwFlags & STRSAFE_FILL_ON_FAILURE) {
1620 memset(pszDest,STRSAFE_GET_FILL_PATTERN(dwFlags),cbDest);
1621 if(STRSAFE_GET_FILL_PATTERN(dwFlags)==0) {
1622 pszDestEnd = pszDest;
1623 cchRemaining = cchDest;
1624 } else if(cchDest > 0) {
1625 pszDestEnd = pszDest + cchDest - 1;
1626 cchRemaining = 1;
1627 *pszDestEnd = '\0';
1628 }
1629 }
1630 if(dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) {
1631 if(cchDest > 0) {
1632 pszDestEnd = pszDest;
1633 cchRemaining = cchDest;
1634 *pszDestEnd = '\0';
1635 }
1636 }
1637 }
1638 }
1639 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER)) {
1640 if(ppszDestEnd) *ppszDestEnd = pszDestEnd;
1641 if(pcchRemaining) *pcchRemaining = cchRemaining;
1642 }
1643 return hr;
1644 }
1645
StringVPrintfExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCWSTR pszFormat,va_list argList)1646 STRSAFEAPI StringVPrintfExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags,STRSAFE_LPCWSTR pszFormat,va_list argList) {
1647 HRESULT hr = S_OK;
1648 STRSAFE_LPWSTR pszDestEnd = pszDest;
1649 size_t cchRemaining = 0;
1650 if(dwFlags & (~STRSAFE_VALID_FLAGS)) hr = STRSAFE_E_INVALID_PARAMETER;
1651 else {
1652 if(dwFlags & STRSAFE_IGNORE_NULLS) {
1653 if(!pszDest) {
1654 if((cchDest!=0) || (cbDest!=0)) hr = STRSAFE_E_INVALID_PARAMETER;
1655 }
1656 if(!pszFormat) pszFormat = L"";
1657 }
1658 if(SUCCEEDED(hr)) {
1659 if(cchDest==0) {
1660 pszDestEnd = pszDest;
1661 cchRemaining = 0;
1662 if(*pszFormat!=L'\0') {
1663 if(!pszDest) hr = STRSAFE_E_INVALID_PARAMETER;
1664 else hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1665 }
1666 } else {
1667 int iRet;
1668 size_t cchMax;
1669 cchMax = cchDest - 1;
1670 iRet = _vsnwprintf(pszDest,cchMax,pszFormat,argList);
1671 if((iRet < 0) || (((size_t)iRet) > cchMax)) {
1672 pszDestEnd = pszDest + cchMax;
1673 cchRemaining = 1;
1674 *pszDestEnd = L'\0';
1675 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1676 } else if(((size_t)iRet)==cchMax) {
1677 pszDestEnd = pszDest + cchMax;
1678 cchRemaining = 1;
1679 *pszDestEnd = L'\0';
1680 } else if(((size_t)iRet) < cchMax) {
1681 pszDestEnd = pszDest + iRet;
1682 cchRemaining = cchDest - iRet;
1683 if(dwFlags & STRSAFE_FILL_BEHIND_NULL) {
1684 memset(pszDestEnd + 1,STRSAFE_GET_FILL_PATTERN(dwFlags),((cchRemaining - 1)*sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)));
1685 }
1686 }
1687 }
1688 }
1689 }
1690 if(FAILED(hr)) {
1691 if(pszDest) {
1692 if(dwFlags & STRSAFE_FILL_ON_FAILURE) {
1693 memset(pszDest,STRSAFE_GET_FILL_PATTERN(dwFlags),cbDest);
1694 if(STRSAFE_GET_FILL_PATTERN(dwFlags)==0) {
1695 pszDestEnd = pszDest;
1696 cchRemaining = cchDest;
1697 } else if(cchDest > 0) {
1698 pszDestEnd = pszDest + cchDest - 1;
1699 cchRemaining = 1;
1700 *pszDestEnd = L'\0';
1701 }
1702 }
1703 if(dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) {
1704 if(cchDest > 0) {
1705 pszDestEnd = pszDest;
1706 cchRemaining = cchDest;
1707 *pszDestEnd = L'\0';
1708 }
1709 }
1710 }
1711 }
1712 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER)) {
1713 if(ppszDestEnd) *ppszDestEnd = pszDestEnd;
1714 if(pcchRemaining) *pcchRemaining = cchRemaining;
1715 }
1716 return hr;
1717 }
1718
StringLengthWorkerA(STRSAFE_LPCSTR psz,size_t cchMax,size_t * pcchLength)1719 STRSAFEAPI StringLengthWorkerA(STRSAFE_LPCSTR psz,size_t cchMax,size_t *pcchLength) {
1720 HRESULT hr = S_OK;
1721 size_t cchMaxPrev = cchMax;
1722 while(cchMax && (*psz!='\0')) {
1723 psz++;
1724 cchMax--;
1725 }
1726 if(cchMax==0) hr = STRSAFE_E_INVALID_PARAMETER;
1727 if(pcchLength) {
1728 if(SUCCEEDED(hr)) *pcchLength = cchMaxPrev - cchMax;
1729 else *pcchLength = 0;
1730 }
1731 return hr;
1732 }
1733
StringLengthWorkerW(STRSAFE_LPCWSTR psz,size_t cchMax,size_t * pcchLength)1734 STRSAFEAPI StringLengthWorkerW(STRSAFE_LPCWSTR psz,size_t cchMax,size_t *pcchLength) {
1735 HRESULT hr = S_OK;
1736 size_t cchMaxPrev = cchMax;
1737 while(cchMax && (*psz!=L'\0')) {
1738 psz++;
1739 cchMax--;
1740 }
1741 if(cchMax==0) hr = STRSAFE_E_INVALID_PARAMETER;
1742 if(pcchLength) {
1743 if(SUCCEEDED(hr)) *pcchLength = cchMaxPrev - cchMax;
1744 else *pcchLength = 0;
1745 }
1746 return hr;
1747 }
1748
StringGetsExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)1749 STRSAFE_INLINE_API StringGetsExWorkerA(STRSAFE_LPSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
1750 HRESULT hr = S_OK;
1751 STRSAFE_LPSTR pszDestEnd = pszDest;
1752 size_t cchRemaining = 0;
1753
1754 if(dwFlags & (~STRSAFE_VALID_FLAGS)) hr = STRSAFE_E_INVALID_PARAMETER;
1755 else {
1756 if(dwFlags & STRSAFE_IGNORE_NULLS) {
1757 if(!pszDest) {
1758 if((cchDest!=0) || (cbDest!=0)) hr = STRSAFE_E_INVALID_PARAMETER;
1759 }
1760 }
1761 if(SUCCEEDED(hr)) {
1762 if(cchDest <= 1) {
1763 pszDestEnd = pszDest;
1764 cchRemaining = cchDest;
1765 if(cchDest==1) *pszDestEnd = '\0';
1766 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1767 } else {
1768 pszDestEnd = pszDest;
1769 cchRemaining = cchDest;
1770 while(cchRemaining > 1) {
1771 char ch;
1772 int i = getc(stdin);
1773 if(i==EOF) {
1774 if(pszDestEnd==pszDest) hr = STRSAFE_E_END_OF_FILE;
1775 break;
1776 }
1777 ch = (char)i;
1778 if(ch=='\n') break;
1779 *pszDestEnd = ch;
1780 pszDestEnd++;
1781 cchRemaining--;
1782 }
1783 if(cchRemaining > 0) {
1784 if(dwFlags & STRSAFE_FILL_BEHIND_NULL) {
1785 memset(pszDestEnd + 1,STRSAFE_GET_FILL_PATTERN(dwFlags),((cchRemaining - 1)*sizeof(char)) + (cbDest % sizeof(char)));
1786 }
1787 }
1788 *pszDestEnd = '\0';
1789 }
1790 }
1791 }
1792 if(FAILED(hr)) {
1793 if(pszDest) {
1794 if(dwFlags & STRSAFE_FILL_ON_FAILURE) {
1795 memset(pszDest,STRSAFE_GET_FILL_PATTERN(dwFlags),cbDest);
1796 if(STRSAFE_GET_FILL_PATTERN(dwFlags)==0) {
1797 pszDestEnd = pszDest;
1798 cchRemaining = cchDest;
1799 } else if(cchDest > 0) {
1800 pszDestEnd = pszDest + cchDest - 1;
1801 cchRemaining = 1;
1802 *pszDestEnd = '\0';
1803 }
1804 }
1805 if(dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) {
1806 if(cchDest > 0) {
1807 pszDestEnd = pszDest;
1808 cchRemaining = cchDest;
1809 *pszDestEnd = '\0';
1810 }
1811 }
1812 }
1813 }
1814 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER) || (hr==STRSAFE_E_END_OF_FILE)) {
1815 if(ppszDestEnd) *ppszDestEnd = pszDestEnd;
1816 if(pcchRemaining) *pcchRemaining = cchRemaining;
1817 }
1818 return hr;
1819 }
1820
StringGetsExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPWSTR * ppszDestEnd,size_t * pcchRemaining,STRSAFE_DWORD dwFlags)1821 STRSAFE_INLINE_API StringGetsExWorkerW(STRSAFE_LPWSTR pszDest,size_t cchDest,size_t cbDest,STRSAFE_LPWSTR *ppszDestEnd,size_t *pcchRemaining,STRSAFE_DWORD dwFlags) {
1822 HRESULT hr = S_OK;
1823 STRSAFE_LPWSTR pszDestEnd = pszDest;
1824 size_t cchRemaining = 0;
1825 if(dwFlags & (~STRSAFE_VALID_FLAGS)) {
1826 hr = STRSAFE_E_INVALID_PARAMETER;
1827 } else {
1828 if(dwFlags & STRSAFE_IGNORE_NULLS) {
1829 if(!pszDest) {
1830 if((cchDest!=0) || (cbDest!=0)) hr = STRSAFE_E_INVALID_PARAMETER;
1831 }
1832 }
1833 if(SUCCEEDED(hr)) {
1834 if(cchDest <= 1) {
1835 pszDestEnd = pszDest;
1836 cchRemaining = cchDest;
1837 if(cchDest==1) *pszDestEnd = L'\0';
1838 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
1839 } else {
1840 pszDestEnd = pszDest;
1841 cchRemaining = cchDest;
1842 while(cchRemaining > 1) {
1843 wchar_t ch = getwc(stdin);
1844 if(ch==WEOF) {
1845 if(pszDestEnd==pszDest) hr = STRSAFE_E_END_OF_FILE;
1846 break;
1847 }
1848 if(ch==L'\n') break;
1849 *pszDestEnd = ch;
1850 pszDestEnd++;
1851 cchRemaining--;
1852 }
1853 if(cchRemaining > 0) {
1854 if(dwFlags & STRSAFE_FILL_BEHIND_NULL) {
1855 memset(pszDestEnd + 1,STRSAFE_GET_FILL_PATTERN(dwFlags),((cchRemaining - 1)*sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)));
1856 }
1857 }
1858 *pszDestEnd = L'\0';
1859 }
1860 }
1861 }
1862 if(FAILED(hr)) {
1863 if(pszDest) {
1864 if(dwFlags & STRSAFE_FILL_ON_FAILURE) {
1865 memset(pszDest,STRSAFE_GET_FILL_PATTERN(dwFlags),cbDest);
1866 if(STRSAFE_GET_FILL_PATTERN(dwFlags)==0) {
1867 pszDestEnd = pszDest;
1868 cchRemaining = cchDest;
1869 } else if(cchDest > 0) {
1870 pszDestEnd = pszDest + cchDest - 1;
1871 cchRemaining = 1;
1872 *pszDestEnd = L'\0';
1873 }
1874 }
1875 if(dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) {
1876 if(cchDest > 0) {
1877 pszDestEnd = pszDest;
1878 cchRemaining = cchDest;
1879 *pszDestEnd = L'\0';
1880 }
1881 }
1882 }
1883 }
1884 if(SUCCEEDED(hr) || (hr==STRSAFE_E_INSUFFICIENT_BUFFER) || (hr==STRSAFE_E_END_OF_FILE)) {
1885 if(ppszDestEnd) *ppszDestEnd = pszDestEnd;
1886 if(pcchRemaining) *pcchRemaining = cchRemaining;
1887 }
1888 return hr;
1889 }
1890 #endif /* !__CRT__NO_INLINE */
1891
1892 #define StringCopyWorkerA StringCopyWorkerA_instead_use_StringCchCopyA_or_StringCchCopyExA;
1893 #define StringCopyWorkerW StringCopyWorkerW_instead_use_StringCchCopyW_or_StringCchCopyExW;
1894 #define StringCopyExWorkerA StringCopyExWorkerA_instead_use_StringCchCopyA_or_StringCchCopyExA;
1895 #define StringCopyExWorkerW StringCopyExWorkerW_instead_use_StringCchCopyW_or_StringCchCopyExW;
1896 #define StringCatWorkerA StringCatWorkerA_instead_use_StringCchCatA_or_StringCchCatExA;
1897 #define StringCatWorkerW StringCatWorkerW_instead_use_StringCchCatW_or_StringCchCatExW;
1898 #define StringCatExWorkerA StringCatExWorkerA_instead_use_StringCchCatA_or_StringCchCatExA;
1899 #define StringCatExWorkerW StringCatExWorkerW_instead_use_StringCchCatW_or_StringCchCatExW;
1900 #define StringCatNWorkerA StringCatNWorkerA_instead_use_StringCchCatNA_or_StrincCbCatNA;
1901 #define StringCatNWorkerW StringCatNWorkerW_instead_use_StringCchCatNW_or_StringCbCatNW;
1902 #define StringCatNExWorkerA StringCatNExWorkerA_instead_use_StringCchCatNExA_or_StringCbCatNExA;
1903 #define StringCatNExWorkerW StringCatNExWorkerW_instead_use_StringCchCatNExW_or_StringCbCatNExW;
1904 #define StringVPrintfWorkerA StringVPrintfWorkerA_instead_use_StringCchVPrintfA_or_StringCchVPrintfExA;
1905 #define StringVPrintfWorkerW StringVPrintfWorkerW_instead_use_StringCchVPrintfW_or_StringCchVPrintfExW;
1906 #define StringVPrintfExWorkerA StringVPrintfExWorkerA_instead_use_StringCchVPrintfA_or_StringCchVPrintfExA;
1907 #define StringVPrintfExWorkerW StringVPrintfExWorkerW_instead_use_StringCchVPrintfW_or_StringCchVPrintfExW;
1908 #define StringLengthWorkerA StringLengthWorkerA_instead_use_StringCchLengthA_or_StringCbLengthA;
1909 #define StringLengthWorkerW StringLengthWorkerW_instead_use_StringCchLengthW_or_StringCbLengthW;
1910 #define StringGetsExWorkerA StringGetsExWorkerA_instead_use_StringCchGetsA_or_StringCbGetsA
1911 #define StringGetsExWorkerW StringGetsExWorkerW_instead_use_StringCchGetsW_or_StringCbGetsW
1912
1913 /* Some Wine modules include us, don't specify STRSAFE_NO_DEPRECATE, and use deprecated functions */
1914 #ifndef STRSAFE_NO_DEPRECATE
1915 #define STRSAFE_NO_DEPRECATE
1916 #endif
1917
1918 #ifndef STRSAFE_NO_DEPRECATE
1919
1920 #undef strcpy
1921 #define strcpy strcpy_instead_use_StringCbCopyA_or_StringCchCopyA;
1922
1923 #undef wcscpy
1924 #define wcscpy wcscpy_instead_use_StringCbCopyW_or_StringCchCopyW;
1925
1926 #undef strcat
1927 #define strcat strcat_instead_use_StringCbCatA_or_StringCchCatA;
1928
1929 #undef wcscat
1930 #define wcscat wcscat_instead_use_StringCbCatW_or_StringCchCatW;
1931
1932 #undef sprintf
1933 #define sprintf sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA;
1934
1935 #undef swprintf
1936 #define swprintf swprintf_instead_use_StringCbPrintfW_or_StringCchPrintfW;
1937
1938 #undef vsprintf
1939 #define vsprintf vsprintf_instead_use_StringCbVPrintfA_or_StringCchVPrintfA;
1940
1941 #undef vswprintf
1942 #define vswprintf vswprintf_instead_use_StringCbVPrintfW_or_StringCchVPrintfW;
1943
1944 #undef _snprintf
1945 #define _snprintf _snprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA;
1946
1947 #undef _snwprintf
1948 #define _snwprintf _snwprintf_instead_use_StringCbPrintfW_or_StringCchPrintfW;
1949
1950 #undef _vsnprintf
1951 #define _vsnprintf _vsnprintf_instead_use_StringCbVPrintfA_or_StringCchVPrintfA;
1952
1953 #undef _vsnwprintf
1954 #define _vsnwprintf _vsnwprintf_instead_use_StringCbVPrintfW_or_StringCchVPrintfW;
1955
1956 #undef strcpyA
1957 #define strcpyA strcpyA_instead_use_StringCbCopyA_or_StringCchCopyA;
1958
1959 #undef strcpyW
1960 #define strcpyW strcpyW_instead_use_StringCbCopyW_or_StringCchCopyW;
1961
1962 #undef lstrcpy
1963 #define lstrcpy lstrcpy_instead_use_StringCbCopy_or_StringCchCopy;
1964
1965 #undef lstrcpyA
1966 #define lstrcpyA lstrcpyA_instead_use_StringCbCopyA_or_StringCchCopyA;
1967
1968 #undef lstrcpyW
1969 #define lstrcpyW lstrcpyW_instead_use_StringCbCopyW_or_StringCchCopyW;
1970
1971 #undef StrCpy
1972 #define StrCpy StrCpy_instead_use_StringCbCopy_or_StringCchCopy;
1973
1974 #undef StrCpyA
1975 #define StrCpyA StrCpyA_instead_use_StringCbCopyA_or_StringCchCopyA;
1976
1977 #undef StrCpyW
1978 #define StrCpyW StrCpyW_instead_use_StringCbCopyW_or_StringCchCopyW;
1979
1980 #undef _tcscpy
1981 #define _tcscpy _tcscpy_instead_use_StringCbCopy_or_StringCchCopy;
1982
1983 #undef _ftcscpy
1984 #define _ftcscpy _ftcscpy_instead_use_StringCbCopy_or_StringCchCopy;
1985
1986 #undef lstrcat
1987 #define lstrcat lstrcat_instead_use_StringCbCat_or_StringCchCat;
1988
1989 #undef lstrcatA
1990 #define lstrcatA lstrcatA_instead_use_StringCbCatA_or_StringCchCatA;
1991
1992 #undef lstrcatW
1993 #define lstrcatW lstrcatW_instead_use_StringCbCatW_or_StringCchCatW;
1994
1995 #undef StrCat
1996 #define StrCat StrCat_instead_use_StringCbCat_or_StringCchCat;
1997
1998 #undef StrCatA
1999 #define StrCatA StrCatA_instead_use_StringCbCatA_or_StringCchCatA;
2000
2001 #undef StrCatW
2002 #define StrCatW StrCatW_instead_use_StringCbCatW_or_StringCchCatW;
2003
2004 #undef StrNCat
2005 #define StrNCat StrNCat_instead_use_StringCbCatN_or_StringCchCatN;
2006
2007 #undef StrNCatA
2008 #define StrNCatA StrNCatA_instead_use_StringCbCatNA_or_StringCchCatNA;
2009
2010 #undef StrNCatW
2011 #define StrNCatW StrNCatW_instead_use_StringCbCatNW_or_StringCchCatNW;
2012
2013 #undef StrCatN
2014 #define StrCatN StrCatN_instead_use_StringCbCatN_or_StringCchCatN;
2015
2016 #undef StrCatNA
2017 #define StrCatNA StrCatNA_instead_use_StringCbCatNA_or_StringCchCatNA;
2018
2019 #undef StrCatNW
2020 #define StrCatNW StrCatNW_instead_use_StringCbCatNW_or_StringCchCatNW;
2021
2022 #undef _tcscat
2023 #define _tcscat _tcscat_instead_use_StringCbCat_or_StringCchCat;
2024
2025 #undef _ftcscat
2026 #define _ftcscat _ftcscat_instead_use_StringCbCat_or_StringCchCat;
2027
2028 #undef wsprintf
2029 #define wsprintf wsprintf_instead_use_StringCbPrintf_or_StringCchPrintf;
2030
2031 #undef wsprintfA
2032 #define wsprintfA wsprintfA_instead_use_StringCbPrintfA_or_StringCchPrintfA;
2033
2034 #undef wsprintfW
2035 #define wsprintfW wsprintfW_instead_use_StringCbPrintfW_or_StringCchPrintfW;
2036
2037 #undef wvsprintf
2038 #define wvsprintf wvsprintf_instead_use_StringCbVPrintf_or_StringCchVPrintf;
2039
2040 #undef wvsprintfA
2041 #define wvsprintfA wvsprintfA_instead_use_StringCbVPrintfA_or_StringCchVPrintfA;
2042
2043 #undef wvsprintfW
2044 #define wvsprintfW wvsprintfW_instead_use_StringCbVPrintfW_or_StringCchVPrintfW;
2045
2046 #undef _vstprintf
2047 #define _vstprintf _vstprintf_instead_use_StringCbVPrintf_or_StringCchVPrintf;
2048
2049 #undef _vsntprintf
2050 #define _vsntprintf _vsntprintf_instead_use_StringCbVPrintf_or_StringCchVPrintf;
2051
2052 #undef _stprintf
2053 #define _stprintf _stprintf_instead_use_StringCbPrintf_or_StringCchPrintf;
2054
2055 #undef _sntprintf
2056 #define _sntprintf _sntprintf_instead_use_StringCbPrintf_or_StringCchPrintf;
2057
2058 #undef _getts
2059 #define _getts _getts_instead_use_StringCbGets_or_StringCchGets;
2060
2061 #undef gets
2062 #define gets _gets_instead_use_StringCbGetsA_or_StringCchGetsA;
2063
2064 #undef _getws
2065 #define _getws _getws_instead_use_StringCbGetsW_or_StringCchGetsW;
2066 #endif
2067
2068 #ifdef __clang__
2069 #pragma clang diagnostic pop
2070 #endif
2071
2072 #endif /* _STRSAFE_H_INCLUDED_ */
2073