annotate lib/legacy_dx/strsafe.h @ 144:38a1c8ef6874

25.11.12
author Ritor1
date Sun, 25 Nov 2012 00:09:29 +0600
parents 8b8875f5b359
children
rev   line source
0
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1 /******************************************************************
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2 * *
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3 * strsafe.h -- This module defines safer C library string *
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4 * routine replacements. These are meant to make C *
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5 * a bit more safe in reference to security and *
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6 * robustness *
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
7 * *
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
8 * Copyright (c) Microsoft Corp. All rights reserved. *
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
9 * *
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
10 ******************************************************************/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
11 #ifndef _STRSAFE_H_INCLUDED_
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
12 #define _STRSAFE_H_INCLUDED_
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
13 #pragma once
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
14
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
15 #include <stdio.h> // for _vsnprintf, _vsnwprintf, getc, getwc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
16 #include <string.h> // for memset
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
17 #include <stdarg.h> // for va_start, etc.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
18
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
19
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
20 #ifndef _SIZE_T_DEFINED
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
21 #ifdef _WIN64
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
22 typedef unsigned __int64 size_t;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
23 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
24 typedef __w64 unsigned int size_t;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
25 #endif // !_WIN64
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
26 #define _SIZE_T_DEFINED
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
27 #endif // !_SIZE_T_DEFINED
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
28
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
29 #if !defined(_WCHAR_T_DEFINED) && !defined(_NATIVE_WCHAR_T_DEFINED)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
30 typedef unsigned short wchar_t;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
31 #define _WCHAR_T_DEFINED
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
32 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
33
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
34 #ifndef _HRESULT_DEFINED
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
35 #define _HRESULT_DEFINED
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
36 typedef long HRESULT;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
37 #endif // !_HRESULT_DEFINED
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
38
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
39 #ifndef SUCCEEDED
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
40 #define SUCCEEDED(hr) ((HRESULT)(hr) >= 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
41 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
42
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
43 #ifndef FAILED
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
44 #define FAILED(hr) ((HRESULT)(hr) < 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
45 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
46
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
47 #ifndef S_OK
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
48 #define S_OK ((HRESULT)0x00000000L)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
49 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
50
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
51 #ifdef __cplusplus
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
52 #define _STRSAFE_EXTERN_C extern "C"
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
53 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
54 #define _STRSAFE_EXTERN_C extern
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
55 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
56
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
57 // If you do not want to use these functions inline (and instead want to link w/ strsafe.lib), then
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
58 // #define STRSAFE_LIB before including this header file.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
59 #if defined(STRSAFE_LIB)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
60 #define STRSAFEAPI _STRSAFE_EXTERN_C HRESULT __stdcall
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
61 #pragma comment(lib, "strsafe.lib")
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
62 #elif defined(STRSAFE_LIB_IMPL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
63 #define STRSAFEAPI _STRSAFE_EXTERN_C HRESULT __stdcall
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
64 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
65 #define STRSAFEAPI __inline HRESULT __stdcall
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
66 #define STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
67 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
68
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
69 // Some functions always run inline because they use stdin and we want to avoid building multiple
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
70 // versions of strsafe lib depending on if you use msvcrt, libcmt, etc.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
71 #define STRSAFE_INLINE_API __inline HRESULT __stdcall
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
72
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
73 // The user can request no "Cb" or no "Cch" fuctions, but not both!
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
74 #if defined(STRSAFE_NO_CB_FUNCTIONS) && defined(STRSAFE_NO_CCH_FUNCTIONS)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
75 #error cannot specify both STRSAFE_NO_CB_FUNCTIONS and STRSAFE_NO_CCH_FUNCTIONS !!
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
76 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
77
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
78 // This should only be defined when we are building strsafe.lib
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
79 #ifdef STRSAFE_LIB_IMPL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
80 #define STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
81 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
82
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
83
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
84 // If both strsafe.h and ntstrsafe.h are included, only use definitions from one.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
85 #ifndef _NTSTRSAFE_H_INCLUDED_
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
86
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
87 #define STRSAFE_MAX_CCH 2147483647 // max # of characters we support (same as INT_MAX)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
88
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
89 // Flags for controling the Ex functions
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
90 //
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
91 // STRSAFE_FILL_BYTE(0xFF) 0x000000FF // bottom byte specifies fill pattern
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
92 #define STRSAFE_IGNORE_NULLS 0x00000100 // treat null as TEXT("") -- don't fault on NULL buffers
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
93 #define STRSAFE_FILL_BEHIND_NULL 0x00000200 // fill in extra space behind the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
94 #define STRSAFE_FILL_ON_FAILURE 0x00000400 // on failure, overwrite pszDest with fill pattern and null terminate it
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
95 #define STRSAFE_NULL_ON_FAILURE 0x00000800 // on failure, set *pszDest = TEXT('\0')
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
96 #define STRSAFE_NO_TRUNCATION 0x00001000 // instead of returning a truncated result, copy/append nothing to pszDest and null terminate it
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
97
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
98 #define STRSAFE_VALID_FLAGS (0x000000FF | STRSAFE_IGNORE_NULLS | STRSAFE_FILL_BEHIND_NULL | STRSAFE_FILL_ON_FAILURE | STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
99
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
100 // helper macro to set the fill character and specify buffer filling
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
101 #define STRSAFE_FILL_BYTE(x) ((unsigned long)((x & 0x000000FF) | STRSAFE_FILL_BEHIND_NULL))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
102 #define STRSAFE_FAILURE_BYTE(x) ((unsigned long)((x & 0x000000FF) | STRSAFE_FILL_ON_FAILURE))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
103
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
104 #define STRSAFE_GET_FILL_PATTERN(dwFlags) ((int)(dwFlags & 0x000000FF))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
105
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
106 #endif // _NTSTRSAFE_H_INCLUDED_
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
107
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
108 // STRSAFE error return codes
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
109 //
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
110 #define STRSAFE_E_INSUFFICIENT_BUFFER ((HRESULT)0x8007007AL) // 0x7A = 122L = ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
111 #define STRSAFE_E_INVALID_PARAMETER ((HRESULT)0x80070057L) // 0x57 = 87L = ERROR_INVALID_PARAMETER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
112 #define STRSAFE_E_END_OF_FILE ((HRESULT)0x80070026L) // 0x26 = 38L = ERROR_HANDLE_EOF
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
113
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
114 // prototypes for the worker functions
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
115 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
116 STRSAFEAPI StringCopyWorkerA(char* pszDest, size_t cchDest, const char* pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
117 STRSAFEAPI StringCopyWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
118 STRSAFEAPI StringCopyExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
119 STRSAFEAPI StringCopyExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
120 STRSAFEAPI StringCopyNWorkerA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
121 STRSAFEAPI StringCopyNWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
122 STRSAFEAPI StringCopyNExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, size_t cchSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
123 STRSAFEAPI StringCopyNExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, const wchar_t* pszSrc, size_t cchSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
124 STRSAFEAPI StringCatWorkerA(char* pszDest, size_t cchDest, const char* pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
125 STRSAFEAPI StringCatWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
126 STRSAFEAPI StringCatExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
127 STRSAFEAPI StringCatExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
128 STRSAFEAPI StringCatNWorkerA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchMaxAppend);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
129 STRSAFEAPI StringCatNWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchMaxAppend);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
130 STRSAFEAPI StringCatNExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, size_t cchMaxAppend, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
131 STRSAFEAPI StringCatNExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, const wchar_t* pszSrc, size_t cchMaxAppend, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
132 STRSAFEAPI StringVPrintfWorkerA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
133 STRSAFEAPI StringVPrintfWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszFormat, va_list argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
134 STRSAFEAPI StringVPrintfExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
135 STRSAFEAPI StringVPrintfExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const wchar_t* pszFormat, va_list argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
136 STRSAFEAPI StringLengthWorkerA(const char* psz, size_t cchMax, size_t* pcch);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
137 STRSAFEAPI StringLengthWorkerW(const wchar_t* psz, size_t cchMax, size_t* pcch);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
138 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
139
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
140 #ifndef STRSAFE_LIB_IMPL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
141 // these functions are always inline
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
142 STRSAFE_INLINE_API StringGetsExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
143 STRSAFE_INLINE_API StringGetsExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
144 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
145
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
146 #ifdef _NTSTRSAFE_H_INCLUDED_
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
147 #pragma warning(push)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
148 #pragma warning(disable : 4995)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
149 #endif // _NTSTRSAFE_H_INCLUDED_
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
150
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
151
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
152 #ifndef STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
153 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
154
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
155 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
156 StringCchCopy(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
157 OUT LPTSTR pszDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
158 IN size_t cchDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
159 IN LPCTSTR pszSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
160 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
161
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
162 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
163
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
164 This routine is a safer version of the C built-in function 'strcpy'.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
165 The size of the destination buffer (in characters) is a parameter and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
166 this function will not write past the end of this buffer and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
167 ALWAYS null terminate the destination buffer (unless it is zero length).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
168
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
169 This routine is not a replacement for strncpy. That function will pad the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
170 destination string with extra null termination characters if the count is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
171 greater than the length of the source string, and it will fail to null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
172 terminate the destination string if the source string length is greater
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
173 than or equal to the count. You can not blindly use this instead of strncpy:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
174 it is common for code to use it to "patch" strings and you would introduce
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
175 errors if the code started null terminating in the middle of the string.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
176
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
177 This function returns a hresult, and not a pointer. It returns
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
178 S_OK if the string was copied without truncation and null terminated,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
179 otherwise it will return a failure code. In failure cases as much of
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
180 pszSrc will be copied to pszDest as possible, and pszDest will be null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
181 terminated.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
182
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
183 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
184
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
185 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
186
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
187 cchDest - size of destination buffer in characters.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
188 length must be = (_tcslen(src) + 1) to hold all of the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
189 source including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
190
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
191 pszSrc - source string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
192
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
193 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
194 Behavior is undefined if source and destination strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
195
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
196 pszDest and pszSrc should not be NULL. See StringCchCopyEx if you require
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
197 the handling of NULL values.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
198
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
199 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
200
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
201 S_OK - if there was source data and it was all copied and the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
202 resultant dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
203
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
204 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
205 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
206
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
207 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
208 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
209 - this return value is an indication that the copy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
210 operation failed due to insufficient space. When this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
211 error occurs, the destination buffer is modified to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
212 contain a truncated version of the ideal result and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
213 null terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
214 truncation is ok
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
215
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
216 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
217 return value of this function.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
218
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
219 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
220
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
221 STRSAFEAPI StringCchCopyA(char* pszDest, size_t cchDest, const char* pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
222 STRSAFEAPI StringCchCopyW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
223 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
224 #define StringCchCopy StringCchCopyW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
225 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
226 #define StringCchCopy StringCchCopyA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
227 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
228
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
229 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
230 STRSAFEAPI StringCchCopyA(char* pszDest, size_t cchDest, const char* pszSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
231 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
232 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
233
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
234 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
235 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
236 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
237 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
238 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
239 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
240 hr = StringCopyWorkerA(pszDest, cchDest, pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
241 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
242
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
243 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
244 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
245
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
246 STRSAFEAPI StringCchCopyW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
247 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
248 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
249
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
250 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
251 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
252 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
253 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
254 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
255 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
256 hr = StringCopyWorkerW(pszDest, cchDest, pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
257 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
258
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
259 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
260 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
261 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
262 #endif // !STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
263
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
264
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
265 #ifndef STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
266 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
267
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
268 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
269 StringCbCopy(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
270 OUT LPTSTR pszDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
271 IN size_t cbDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
272 IN LPCTSTR pszSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
273 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
274
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
275 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
276
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
277 This routine is a safer version of the C built-in function 'strcpy'.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
278 The size of the destination buffer (in bytes) is a parameter and this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
279 function will not write past the end of this buffer and it will ALWAYS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
280 null terminate the destination buffer (unless it is zero length).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
281
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
282 This routine is not a replacement for strncpy. That function will pad the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
283 destination string with extra null termination characters if the count is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
284 greater than the length of the source string, and it will fail to null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
285 terminate the destination string if the source string length is greater
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
286 than or equal to the count. You can not blindly use this instead of strncpy:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
287 it is common for code to use it to "patch" strings and you would introduce
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
288 errors if the code started null terminating in the middle of the string.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
289
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
290 This function returns a hresult, and not a pointer. It returns
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
291 S_OK if the string was copied without truncation and null terminated,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
292 otherwise it will return a failure code. In failure cases as much of pszSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
293 will be copied to pszDest as possible, and pszDest will be null terminated.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
294
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
295 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
296
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
297 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
298
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
299 cbDest - size of destination buffer in bytes.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
300 length must be = ((_tcslen(src) + 1) * sizeof(TCHAR)) to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
301 hold all of the source including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
302
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
303 pszSrc - source string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
304
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
305 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
306 Behavior is undefined if source and destination strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
307
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
308 pszDest and pszSrc should not be NULL. See StringCbCopyEx if you require
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
309 the handling of NULL values.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
310
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
311 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
312
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
313 S_OK - if there was source data and it was all copied and the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
314 resultant dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
315
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
316 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
317 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
318
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
319 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
320 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
321 - this return value is an indication that the copy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
322 operation failed due to insufficient space. When this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
323 error occurs, the destination buffer is modified to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
324 contain a truncated version of the ideal result and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
325 null terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
326 truncation is ok
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
327
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
328 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
329 return value of this function.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
330
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
331 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
332
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
333 STRSAFEAPI StringCbCopyA(char* pszDest, size_t cbDest, const char* pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
334 STRSAFEAPI StringCbCopyW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
335 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
336 #define StringCbCopy StringCbCopyW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
337 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
338 #define StringCbCopy StringCbCopyA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
339 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
340
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
341 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
342 STRSAFEAPI StringCbCopyA(char* pszDest, size_t cbDest, const char* pszSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
343 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
344 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
345 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
346
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
347 // convert to count of characters
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
348 cchDest = cbDest / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
349
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
350 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
351 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
352 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
353 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
354 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
355 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
356 hr = StringCopyWorkerA(pszDest, cchDest, pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
357 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
358
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
359 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
360 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
361
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
362 STRSAFEAPI StringCbCopyW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
363 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
364 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
365 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
366
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
367 // convert to count of characters
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
368 cchDest = cbDest / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
369
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
370 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
371 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
372 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
373 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
374 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
375 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
376 hr = StringCopyWorkerW(pszDest, cchDest, pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
377 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
378
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
379 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
380 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
381 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
382 #endif // !STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
383
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
384
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
385 #ifndef STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
386 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
387
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
388 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
389 StringCchCopyEx(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
390 OUT LPTSTR pszDest OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
391 IN size_t cchDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
392 IN LPCTSTR pszSrc OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
393 OUT LPTSTR* ppszDestEnd OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
394 OUT size_t* pcchRemaining OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
395 IN DWORD dwFlags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
396 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
397
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
398 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
399
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
400 This routine is a safer version of the C built-in function 'strcpy' with
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
401 some additional parameters. In addition to functionality provided by
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
402 StringCchCopy, this routine also returns a pointer to the end of the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
403 destination string and the number of characters left in the destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
404 including the null terminator. The flags parameter allows additional controls.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
405
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
406 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
407
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
408 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
409
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
410 cchDest - size of destination buffer in characters.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
411 length must be = (_tcslen(pszSrc) + 1) to hold all of
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
412 the source including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
413
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
414 pszSrc - source string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
415
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
416 ppszDestEnd - if ppszDestEnd is non-null, the function will return a
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
417 pointer to the end of the destination string. If the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
418 function copied any data, the result will point to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
419 null termination character
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
420
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
421 pcchRemaining - if pcchRemaining is non-null, the function will return the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
422 number of characters left in the destination string,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
423 including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
424
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
425 dwFlags - controls some details of the string copy:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
426
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
427 STRSAFE_FILL_BEHIND_NULL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
428 if the function succeeds, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
429 used to fill the uninitialize part of destination buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
430 behind the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
431
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
432 STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
433 treat NULL string pointers like empty strings (TEXT("")).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
434 this flag is useful for emulating functions like lstrcpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
435
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
436 STRSAFE_FILL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
437 if the function fails, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
438 used to fill all of the destination buffer, and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
439 be null terminated. This will overwrite any truncated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
440 string returned when the failure is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
441 STRSAFE_E_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
442
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
443 STRSAFE_NO_TRUNCATION /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
444 STRSAFE_NULL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
445 if the function fails, the destination buffer will be set
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
446 to the empty string. This will overwrite any truncated string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
447 returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
448
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
449 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
450 Behavior is undefined if source and destination strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
451
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
452 pszDest and pszSrc should not be NULL unless the STRSAFE_IGNORE_NULLS flag
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
453 is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and pszSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
454 may be NULL. An error may still be returned even though NULLS are ignored
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
455 due to insufficient space.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
456
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
457 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
458
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
459 S_OK - if there was source data and it was all copied and the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
460 resultant dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
461
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
462 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
463 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
464
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
465 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
466 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
467 - this return value is an indication that the copy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
468 operation failed due to insufficient space. When this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
469 error occurs, the destination buffer is modified to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
470 contain a truncated version of the ideal result and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
471 null terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
472 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
473
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
474 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
475 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
476
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
477 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
478
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
479 STRSAFEAPI StringCchCopyExA(char* pszDest, size_t cchDest, const char* pszSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
480 STRSAFEAPI StringCchCopyExW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
481 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
482 #define StringCchCopyEx StringCchCopyExW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
483 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
484 #define StringCchCopyEx StringCchCopyExA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
485 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
486
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
487 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
488 STRSAFEAPI StringCchCopyExA(char* pszDest, size_t cchDest, const char* pszSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
489 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
490 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
491
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
492 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
493 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
494 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
495 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
496 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
497 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
498 size_t cbDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
499
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
500 // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
501 cbDest = cchDest * sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
502
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
503 hr = StringCopyExWorkerA(pszDest, cchDest, cbDest, pszSrc, ppszDestEnd, pcchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
504 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
505
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
506 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
507 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
508
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
509 STRSAFEAPI StringCchCopyExW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
510 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
511 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
512
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
513 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
514 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
515 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
516 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
517 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
518 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
519 size_t cbDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
520
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
521 // safe to multiply cchDest * sizeof(wchar_t) since cchDest < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
522 cbDest = cchDest * sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
523
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
524 hr = StringCopyExWorkerW(pszDest, cchDest, cbDest, pszSrc, ppszDestEnd, pcchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
525 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
526
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
527 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
528 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
529 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
530 #endif // !STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
531
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
532
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
533 #ifndef STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
534 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
535
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
536 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
537 StringCbCopyEx(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
538 OUT LPTSTR pszDest OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
539 IN size_t cbDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
540 IN LPCTSTR pszSrc OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
541 OUT LPTSTR* ppszDestEnd OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
542 OUT size_t* pcbRemaining OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
543 IN DWORD dwFlags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
544 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
545
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
546 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
547
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
548 This routine is a safer version of the C built-in function 'strcpy' with
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
549 some additional parameters. In addition to functionality provided by
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
550 StringCbCopy, this routine also returns a pointer to the end of the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
551 destination string and the number of bytes left in the destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
552 including the null terminator. The flags parameter allows additional controls.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
553
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
554 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
555
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
556 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
557
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
558 cbDest - size of destination buffer in bytes.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
559 length must be ((_tcslen(pszSrc) + 1) * sizeof(TCHAR)) to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
560 hold all of the source including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
561
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
562 pszSrc - source string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
563
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
564 ppszDestEnd - if ppszDestEnd is non-null, the function will return a
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
565 pointer to the end of the destination string. If the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
566 function copied any data, the result will point to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
567 null termination character
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
568
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
569 pcbRemaining - pcbRemaining is non-null,the function will return the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
570 number of bytes left in the destination string,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
571 including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
572
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
573 dwFlags - controls some details of the string copy:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
574
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
575 STRSAFE_FILL_BEHIND_NULL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
576 if the function succeeds, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
577 used to fill the uninitialize part of destination buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
578 behind the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
579
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
580 STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
581 treat NULL string pointers like empty strings (TEXT("")).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
582 this flag is useful for emulating functions like lstrcpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
583
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
584 STRSAFE_FILL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
585 if the function fails, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
586 used to fill all of the destination buffer, and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
587 be null terminated. This will overwrite any truncated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
588 string returned when the failure is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
589 STRSAFE_E_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
590
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
591 STRSAFE_NO_TRUNCATION /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
592 STRSAFE_NULL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
593 if the function fails, the destination buffer will be set
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
594 to the empty string. This will overwrite any truncated string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
595 returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
596
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
597 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
598 Behavior is undefined if source and destination strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
599
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
600 pszDest and pszSrc should not be NULL unless the STRSAFE_IGNORE_NULLS flag
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
601 is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and pszSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
602 may be NULL. An error may still be returned even though NULLS are ignored
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
603 due to insufficient space.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
604
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
605 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
606
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
607 S_OK - if there was source data and it was all copied and the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
608 resultant dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
609
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
610 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
611 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
612
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
613 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
614 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
615 - this return value is an indication that the copy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
616 operation failed due to insufficient space. When this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
617 error occurs, the destination buffer is modified to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
618 contain a truncated version of the ideal result and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
619 null terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
620 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
621
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
622 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
623 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
624
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
625 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
626
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
627 STRSAFEAPI StringCbCopyExA(char* pszDest, size_t cbDest, const char* pszSrc, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
628 STRSAFEAPI StringCbCopyExW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
629 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
630 #define StringCbCopyEx StringCbCopyExW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
631 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
632 #define StringCbCopyEx StringCbCopyExA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
633 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
634
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
635 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
636 STRSAFEAPI StringCbCopyExA(char* pszDest, size_t cbDest, const char* pszSrc, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
637 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
638 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
639 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
640 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
641
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
642 cchDest = cbDest / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
643
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
644 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
645 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
646 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
647 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
648 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
649 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
650 hr = StringCopyExWorkerA(pszDest, cchDest, cbDest, pszSrc, ppszDestEnd, &cchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
651 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
652
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
653 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
654 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
655 if (pcbRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
656 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
657 // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
658 *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
659 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
660 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
661
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
662 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
663 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
664
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
665 STRSAFEAPI StringCbCopyExW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
666 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
667 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
668 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
669 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
670
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
671 cchDest = cbDest / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
672
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
673 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
674 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
675 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
676 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
677 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
678 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
679 hr = StringCopyExWorkerW(pszDest, cchDest, cbDest, pszSrc, ppszDestEnd, &cchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
680 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
681
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
682 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
683 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
684 if (pcbRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
685 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
686 // safe to multiply cchRemaining * sizeof(wchar_t) since cchRemaining < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
687 *pcbRemaining = (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
688 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
689 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
690
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
691 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
692 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
693 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
694 #endif // !STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
695
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
696
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
697 #ifndef STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
698 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
699
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
700 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
701 StringCchCopyN(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
702 OUT LPTSTR pszDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
703 IN size_t cchDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
704 IN LPCTSTR pszSrc,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
705 IN size_t cchSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
706 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
707
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
708 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
709
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
710 This routine is a safer version of the C built-in function 'strncpy'.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
711 The size of the destination buffer (in characters) is a parameter and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
712 this function will not write past the end of this buffer and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
713 ALWAYS null terminate the destination buffer (unless it is zero length).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
714
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
715 This routine is meant as a replacement for strncpy, but it does behave
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
716 differently. This function will not pad the destination buffer with extra
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
717 null termination characters if cchSrc is greater than the length of pszSrc.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
718
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
719 This function returns a hresult, and not a pointer. It returns
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
720 S_OK if the entire string or the first cchSrc characters were copied
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
721 without truncation and the resultant destination string was null terminated,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
722 otherwise it will return a failure code. In failure cases as much of pszSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
723 will be copied to pszDest as possible, and pszDest will be null terminated.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
724
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
725 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
726
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
727 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
728
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
729 cchDest - size of destination buffer in characters.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
730 length must be = (_tcslen(src) + 1) to hold all of the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
731 source including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
732
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
733 pszSrc - source string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
734
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
735 cchSrc - maximum number of characters to copy from source string,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
736 not including the null terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
737
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
738 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
739 Behavior is undefined if source and destination strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
740
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
741 pszDest and pszSrc should not be NULL. See StringCchCopyNEx if you require
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
742 the handling of NULL values.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
743
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
744 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
745
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
746 S_OK - if there was source data and it was all copied and the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
747 resultant dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
748
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
749 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
750 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
751
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
752 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
753 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
754 - this return value is an indication that the copy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
755 operation failed due to insufficient space. When this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
756 error occurs, the destination buffer is modified to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
757 contain a truncated version of the ideal result and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
758 null terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
759 truncation is ok
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
760
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
761 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
762 return value of this function.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
763
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
764 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
765
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
766 STRSAFEAPI StringCchCopyNA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
767 STRSAFEAPI StringCchCopyNW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
768 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
769 #define StringCchCopyN StringCchCopyNW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
770 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
771 #define StringCchCopyN StringCchCopyNA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
772 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
773
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
774 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
775 STRSAFEAPI StringCchCopyNA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
776 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
777 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
778
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
779 if ((cchDest > STRSAFE_MAX_CCH) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
780 (cchSrc > STRSAFE_MAX_CCH))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
781 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
782 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
783 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
784 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
785 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
786 hr = StringCopyNWorkerA(pszDest, cchDest, pszSrc, cchSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
787 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
788
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
789 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
790 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
791
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
792 STRSAFEAPI StringCchCopyNW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
793 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
794 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
795
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
796 if ((cchDest > STRSAFE_MAX_CCH) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
797 (cchSrc > STRSAFE_MAX_CCH))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
798 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
799 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
800 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
801 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
802 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
803 hr = StringCopyNWorkerW(pszDest, cchDest, pszSrc, cchSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
804 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
805
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
806 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
807 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
808 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
809 #endif // !STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
810
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
811
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
812 #ifndef STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
813 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
814
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
815 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
816 StringCbCopyN(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
817 OUT LPTSTR pszDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
818 IN size_t cbDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
819 IN LPCTSTR pszSrc,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
820 IN size_t cbSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
821 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
822
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
823 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
824
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
825 This routine is a safer version of the C built-in function 'strncpy'.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
826 The size of the destination buffer (in bytes) is a parameter and this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
827 function will not write past the end of this buffer and it will ALWAYS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
828 null terminate the destination buffer (unless it is zero length).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
829
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
830 This routine is meant as a replacement for strncpy, but it does behave
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
831 differently. This function will not pad the destination buffer with extra
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
832 null termination characters if cbSrc is greater than the size of pszSrc.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
833
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
834 This function returns a hresult, and not a pointer. It returns
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
835 S_OK if the entire string or the first cbSrc characters were
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
836 copied without truncation and the resultant destination string was null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
837 terminated, otherwise it will return a failure code. In failure cases as
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
838 much of pszSrc will be copied to pszDest as possible, and pszDest will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
839 null terminated.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
840
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
841 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
842
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
843 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
844
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
845 cbDest - size of destination buffer in bytes.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
846 length must be = ((_tcslen(src) + 1) * sizeof(TCHAR)) to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
847 hold all of the source including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
848
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
849 pszSrc - source string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
850
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
851 cbSrc - maximum number of bytes to copy from source string,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
852 not including the null terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
853
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
854 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
855 Behavior is undefined if source and destination strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
856
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
857 pszDest and pszSrc should not be NULL. See StringCbCopyEx if you require
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
858 the handling of NULL values.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
859
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
860 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
861
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
862 S_OK - if there was source data and it was all copied and the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
863 resultant dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
864
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
865 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
866 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
867
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
868 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
869 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
870 - this return value is an indication that the copy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
871 operation failed due to insufficient space. When this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
872 error occurs, the destination buffer is modified to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
873 contain a truncated version of the ideal result and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
874 null terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
875 truncation is ok
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
876
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
877 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
878 return value of this function.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
879
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
880 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
881
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
882 STRSAFEAPI StringCbCopyNA(char* pszDest, size_t cbDest, const char* pszSrc, size_t cbSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
883 STRSAFEAPI StringCbCopyNW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, size_t cbSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
884 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
885 #define StringCbCopyN StringCbCopyNW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
886 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
887 #define StringCbCopyN StringCbCopyNA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
888 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
889
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
890 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
891 STRSAFEAPI StringCbCopyNA(char* pszDest, size_t cbDest, const char* pszSrc, size_t cbSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
892 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
893 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
894 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
895 size_t cchSrc;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
896
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
897 // convert to count of characters
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
898 cchDest = cbDest / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
899 cchSrc = cbSrc / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
900
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
901 if ((cchDest > STRSAFE_MAX_CCH) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
902 (cchSrc > STRSAFE_MAX_CCH))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
903 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
904 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
905 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
906 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
907 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
908 hr = StringCopyNWorkerA(pszDest, cchDest, pszSrc, cchSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
909 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
910
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
911 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
912 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
913
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
914 STRSAFEAPI StringCbCopyNW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, size_t cbSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
915 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
916 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
917 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
918 size_t cchSrc;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
919
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
920 // convert to count of characters
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
921 cchDest = cbDest / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
922 cchSrc = cbSrc / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
923
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
924 if ((cchDest > STRSAFE_MAX_CCH) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
925 (cchSrc > STRSAFE_MAX_CCH))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
926 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
927 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
928 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
929 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
930 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
931 hr = StringCopyNWorkerW(pszDest, cchDest, pszSrc, cchSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
932 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
933
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
934 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
935 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
936 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
937 #endif // !STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
938
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
939
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
940 #ifndef STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
941 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
942
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
943 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
944 StringCchCopyNEx(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
945 OUT LPTSTR pszDest OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
946 IN size_t cchDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
947 IN LPCTSTR pszSrc OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
948 IN size_t cchSrc,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
949 OUT LPTSTR* ppszDestEnd OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
950 OUT size_t* pcchRemaining OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
951 IN DWORD dwFlags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
952 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
953
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
954 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
955
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
956 This routine is a safer version of the C built-in function 'strncpy' with
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
957 some additional parameters. In addition to functionality provided by
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
958 StringCchCopyN, this routine also returns a pointer to the end of the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
959 destination string and the number of characters left in the destination
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
960 string including the null terminator. The flags parameter allows
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
961 additional controls.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
962
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
963 This routine is meant as a replacement for strncpy, but it does behave
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
964 differently. This function will not pad the destination buffer with extra
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
965 null termination characters if cchSrc is greater than the length of pszSrc.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
966
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
967 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
968
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
969 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
970
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
971 cchDest - size of destination buffer in characters.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
972 length must be = (_tcslen(pszSrc) + 1) to hold all of
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
973 the source including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
974
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
975 pszSrc - source string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
976
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
977 cchSrc - maximum number of characters to copy from the source
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
978 string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
979
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
980 ppszDestEnd - if ppszDestEnd is non-null, the function will return a
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
981 pointer to the end of the destination string. If the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
982 function copied any data, the result will point to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
983 null termination character
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
984
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
985 pcchRemaining - if pcchRemaining is non-null, the function will return the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
986 number of characters left in the destination string,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
987 including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
988
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
989 dwFlags - controls some details of the string copy:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
990
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
991 STRSAFE_FILL_BEHIND_NULL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
992 if the function succeeds, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
993 used to fill the uninitialize part of destination buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
994 behind the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
995
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
996 STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
997 treat NULL string pointers like empty strings (TEXT("")).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
998 this flag is useful for emulating functions like lstrcpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
999
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1000 STRSAFE_FILL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1001 if the function fails, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1002 used to fill all of the destination buffer, and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1003 be null terminated. This will overwrite any truncated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1004 string returned when the failure is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1005 STRSAFE_E_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1006
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1007 STRSAFE_NO_TRUNCATION /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1008 STRSAFE_NULL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1009 if the function fails, the destination buffer will be set
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1010 to the empty string. This will overwrite any truncated string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1011 returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1012
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1013 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1014 Behavior is undefined if source and destination strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1015
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1016 pszDest and pszSrc should not be NULL unless the STRSAFE_IGNORE_NULLS flag
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1017 is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and pszSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1018 may be NULL. An error may still be returned even though NULLS are ignored
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1019 due to insufficient space.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1020
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1021 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1022
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1023 S_OK - if there was source data and it was all copied and the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1024 resultant dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1025
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1026 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1027 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1028
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1029 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1030 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1031 - this return value is an indication that the copy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1032 operation failed due to insufficient space. When this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1033 error occurs, the destination buffer is modified to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1034 contain a truncated version of the ideal result and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1035 null terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1036 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1037
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1038 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1039 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1040
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1041 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1042
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1043 STRSAFEAPI StringCchCopyNExA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1044 STRSAFEAPI StringCchCopyNExW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1045 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1046 #define StringCchCopyNEx StringCchCopyNExW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1047 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1048 #define StringCchCopyNEx StringCchCopyNExA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1049 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1050
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1051 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1052 STRSAFEAPI StringCchCopyNExA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1053 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1054 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1055
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1056 if ((cchDest > STRSAFE_MAX_CCH) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1057 (cchSrc > STRSAFE_MAX_CCH))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1058 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1059 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1060 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1061 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1062 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1063 size_t cbDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1064
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1065 // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1066 cbDest = cchDest * sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1067
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1068 hr = StringCopyNExWorkerA(pszDest, cchDest, cbDest, pszSrc, cchSrc, ppszDestEnd, pcchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1069 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1070
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1071 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1072 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1073
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1074 STRSAFEAPI StringCchCopyNExW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1075 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1076 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1077
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1078 if ((cchDest > STRSAFE_MAX_CCH) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1079 (cchSrc > STRSAFE_MAX_CCH))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1080 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1081 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1082 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1083 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1084 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1085 size_t cbDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1086
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1087 // safe to multiply cchDest * sizeof(wchar_t) since cchDest < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1088 cbDest = cchDest * sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1089
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1090 hr = StringCopyNExWorkerW(pszDest, cchDest, cbDest, pszSrc, cchSrc, ppszDestEnd, pcchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1091 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1092
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1093 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1094 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1095 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1096 #endif // !STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1097
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1098
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1099 #ifndef STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1100 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1101
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1102 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1103 StringCbCopyNEx(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1104 OUT LPTSTR pszDest OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1105 IN size_t cbDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1106 IN LPCTSTR pszSrc OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1107 IN size_t cbSrc,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1108 OUT LPTSTR* ppszDestEnd OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1109 OUT size_t* pcbRemaining OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1110 IN DWORD dwFlags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1111 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1112
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1113 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1114
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1115 This routine is a safer version of the C built-in function 'strncpy' with
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1116 some additional parameters. In addition to functionality provided by
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1117 StringCbCopyN, this routine also returns a pointer to the end of the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1118 destination string and the number of bytes left in the destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1119 including the null terminator. The flags parameter allows additional controls.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1120
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1121 This routine is meant as a replacement for strncpy, but it does behave
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1122 differently. This function will not pad the destination buffer with extra
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1123 null termination characters if cbSrc is greater than the size of pszSrc.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1124
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1125 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1126
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1127 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1128
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1129 cbDest - size of destination buffer in bytes.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1130 length must be ((_tcslen(pszSrc) + 1) * sizeof(TCHAR)) to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1131 hold all of the source including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1132
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1133 pszSrc - source string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1134
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1135 cbSrc - maximum number of bytes to copy from source string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1136
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1137 ppszDestEnd - if ppszDestEnd is non-null, the function will return a
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1138 pointer to the end of the destination string. If the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1139 function copied any data, the result will point to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1140 null termination character
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1141
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1142 pcbRemaining - pcbRemaining is non-null,the function will return the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1143 number of bytes left in the destination string,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1144 including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1145
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1146 dwFlags - controls some details of the string copy:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1147
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1148 STRSAFE_FILL_BEHIND_NULL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1149 if the function succeeds, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1150 used to fill the uninitialize part of destination buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1151 behind the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1152
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1153 STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1154 treat NULL string pointers like empty strings (TEXT("")).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1155 this flag is useful for emulating functions like lstrcpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1156
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1157 STRSAFE_FILL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1158 if the function fails, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1159 used to fill all of the destination buffer, and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1160 be null terminated. This will overwrite any truncated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1161 string returned when the failure is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1162 STRSAFE_E_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1163
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1164 STRSAFE_NO_TRUNCATION /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1165 STRSAFE_NULL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1166 if the function fails, the destination buffer will be set
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1167 to the empty string. This will overwrite any truncated string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1168 returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1169
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1170 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1171 Behavior is undefined if source and destination strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1172
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1173 pszDest and pszSrc should not be NULL unless the STRSAFE_IGNORE_NULLS flag
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1174 is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and pszSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1175 may be NULL. An error may still be returned even though NULLS are ignored
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1176 due to insufficient space.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1177
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1178 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1179
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1180 S_OK - if there was source data and it was all copied and the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1181 resultant dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1182
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1183 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1184 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1185
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1186 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1187 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1188 - this return value is an indication that the copy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1189 operation failed due to insufficient space. When this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1190 error occurs, the destination buffer is modified to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1191 contain a truncated version of the ideal result and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1192 null terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1193 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1194
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1195 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1196 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1197
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1198 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1199
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1200 STRSAFEAPI StringCbCopyNExA(char* pszDest, size_t cbDest, const char* pszSrc, size_t cbSrc, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1201 STRSAFEAPI StringCbCopyNExW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, size_t cbSrc, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1202 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1203 #define StringCbCopyNEx StringCbCopyNExW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1204 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1205 #define StringCbCopyNEx StringCbCopyNExA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1206 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1207
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1208 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1209 STRSAFEAPI StringCbCopyNExA(char* pszDest, size_t cbDest, const char* pszSrc, size_t cbSrc, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1210 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1211 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1212 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1213 size_t cchSrc;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1214 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1215
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1216 cchDest = cbDest / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1217 cchSrc = cbSrc / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1218
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1219 if ((cchDest > STRSAFE_MAX_CCH) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1220 (cchSrc > STRSAFE_MAX_CCH))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1221 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1222 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1223 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1224 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1225 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1226 hr = StringCopyNExWorkerA(pszDest, cchDest, cbDest, pszSrc, cchSrc, ppszDestEnd, &cchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1227 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1228
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1229 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1230 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1231 if (pcbRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1232 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1233 // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1234 *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1235 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1236 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1237
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1238 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1239 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1240
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1241 STRSAFEAPI StringCbCopyNExW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, size_t cbSrc, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1242 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1243 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1244 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1245 size_t cchSrc;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1246 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1247
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1248 cchDest = cbDest / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1249 cchSrc = cbSrc / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1250
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1251 if ((cchDest > STRSAFE_MAX_CCH) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1252 (cchSrc > STRSAFE_MAX_CCH))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1253 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1254 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1255 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1256 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1257 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1258 hr = StringCopyNExWorkerW(pszDest, cchDest, cbDest, pszSrc, cchSrc, ppszDestEnd, &cchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1259 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1260
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1261 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1262 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1263 if (pcbRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1264 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1265 // safe to multiply cchRemaining * sizeof(wchar_t) since cchRemaining < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1266 *pcbRemaining = (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1267 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1268 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1269
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1270 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1271 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1272 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1273 #endif // !STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1274
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1275
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1276 #ifndef STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1277 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1278
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1279 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1280 StringCchCat(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1281 IN OUT LPTSTR pszDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1282 IN size_t cchDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1283 IN LPCTSTR pszSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1284 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1285
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1286 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1287
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1288 This routine is a safer version of the C built-in function 'strcat'.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1289 The size of the destination buffer (in characters) is a parameter and this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1290 function will not write past the end of this buffer and it will ALWAYS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1291 null terminate the destination buffer (unless it is zero length).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1292
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1293 This function returns a hresult, and not a pointer. It returns
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1294 S_OK if the string was concatenated without truncation and null terminated,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1295 otherwise it will return a failure code. In failure cases as much of pszSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1296 will be appended to pszDest as possible, and pszDest will be null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1297 terminated.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1298
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1299 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1300
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1301 pszDest - destination string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1302
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1303 cchDest - size of destination buffer in characters.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1304 length must be = (_tcslen(pszDest) + _tcslen(pszSrc) + 1)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1305 to hold all of the combine string plus the null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1306 terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1307
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1308 pszSrc - source string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1309
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1310 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1311 Behavior is undefined if source and destination strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1312
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1313 pszDest and pszSrc should not be NULL. See StringCchCatEx if you require
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1314 the handling of NULL values.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1315
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1316 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1317
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1318 S_OK - if there was source data and it was all concatenated and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1319 the resultant dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1320
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1321 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1322 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1323
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1324 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1325 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1326 - this return value is an indication that the operation
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1327 failed due to insufficient space. When this error occurs,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1328 the destination buffer is modified to contain a truncated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1329 version of the ideal result and is null terminated. This
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1330 is useful for situations where truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1331
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1332 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1333 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1334
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1335 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1336
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1337 STRSAFEAPI StringCchCatA(char* pszDest, size_t cchDest, const char* pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1338 STRSAFEAPI StringCchCatW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1339 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1340 #define StringCchCat StringCchCatW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1341 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1342 #define StringCchCat StringCchCatA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1343 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1344
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1345 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1346 STRSAFEAPI StringCchCatA(char* pszDest, size_t cchDest, const char* pszSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1347 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1348 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1349
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1350 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1351 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1352 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1353 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1354 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1355 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1356 hr = StringCatWorkerA(pszDest, cchDest, pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1357 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1358
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1359 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1360 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1361
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1362 STRSAFEAPI StringCchCatW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1363 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1364 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1365
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1366 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1367 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1368 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1369 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1370 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1371 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1372 hr = StringCatWorkerW(pszDest, cchDest, pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1373 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1374
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1375 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1376 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1377 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1378 #endif // !STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1379
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1380
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1381 #ifndef STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1382 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1383
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1384 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1385 StringCbCat(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1386 IN OUT LPTSTR pszDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1387 IN size_t cbDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1388 IN LPCTSTR pszSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1389 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1390
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1391 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1392
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1393 This routine is a safer version of the C built-in function 'strcat'.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1394 The size of the destination buffer (in bytes) is a parameter and this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1395 function will not write past the end of this buffer and it will ALWAYS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1396 null terminate the destination buffer (unless it is zero length).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1397
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1398 This function returns a hresult, and not a pointer. It returns
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1399 S_OK if the string was concatenated without truncation and null terminated,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1400 otherwise it will return a failure code. In failure cases as much of pszSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1401 will be appended to pszDest as possible, and pszDest will be null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1402 terminated.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1403
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1404 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1405
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1406 pszDest - destination string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1407
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1408 cbDest - size of destination buffer in bytes.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1409 length must be = ((_tcslen(pszDest) + _tcslen(pszSrc) + 1) * sizeof(TCHAR)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1410 to hold all of the combine string plus the null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1411 terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1412
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1413 pszSrc - source string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1414
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1415 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1416 Behavior is undefined if source and destination strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1417
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1418 pszDest and pszSrc should not be NULL. See StringCbCatEx if you require
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1419 the handling of NULL values.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1420
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1421 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1422
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1423 S_OK - if there was source data and it was all concatenated and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1424 the resultant dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1425
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1426 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1427 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1428
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1429 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1430 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1431 - this return value is an indication that the operation
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1432 failed due to insufficient space. When this error occurs,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1433 the destination buffer is modified to contain a truncated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1434 version of the ideal result and is null terminated. This
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1435 is useful for situations where truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1436
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1437 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1438 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1439
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1440 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1441
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1442 STRSAFEAPI StringCbCatA(char* pszDest, size_t cbDest, const char* pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1443 STRSAFEAPI StringCbCatW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1444 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1445 #define StringCbCat StringCbCatW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1446 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1447 #define StringCbCat StringCbCatA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1448 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1449
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1450 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1451 STRSAFEAPI StringCbCatA(char* pszDest, size_t cbDest, const char* pszSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1452 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1453 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1454 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1455
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1456 cchDest = cbDest / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1457
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1458 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1459 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1460 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1461 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1462 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1463 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1464 hr = StringCatWorkerA(pszDest, cchDest, pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1465 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1466
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1467 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1468 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1469
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1470 STRSAFEAPI StringCbCatW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1471 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1472 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1473 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1474
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1475 cchDest = cbDest / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1476
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1477 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1478 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1479 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1480 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1481 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1482 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1483 hr = StringCatWorkerW(pszDest, cchDest, pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1484 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1485
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1486 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1487 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1488 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1489 #endif // !STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1490
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1491
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1492 #ifndef STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1493 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1494
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1495 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1496 StringCchCatEx(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1497 IN OUT LPTSTR pszDest OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1498 IN size_t cchDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1499 IN LPCTSTR pszSrc OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1500 OUT LPTSTR* ppszDestEnd OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1501 OUT size_t* pcchRemaining OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1502 IN DWORD dwFlags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1503 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1504
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1505 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1506
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1507 This routine is a safer version of the C built-in function 'strcat' with
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1508 some additional parameters. In addition to functionality provided by
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1509 StringCchCat, this routine also returns a pointer to the end of the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1510 destination string and the number of characters left in the destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1511 including the null terminator. The flags parameter allows additional controls.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1512
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1513 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1514
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1515 pszDest - destination string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1516
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1517 cchDest - size of destination buffer in characters
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1518 length must be (_tcslen(pszDest) + _tcslen(pszSrc) + 1)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1519 to hold all of the combine string plus the null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1520 terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1521
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1522 pszSrc - source string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1523
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1524 ppszDestEnd - if ppszDestEnd is non-null, the function will return a
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1525 pointer to the end of the destination string. If the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1526 function appended any data, the result will point to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1527 null termination character
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1528
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1529 pcchRemaining - if pcchRemaining is non-null, the function will return the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1530 number of characters left in the destination string,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1531 including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1532
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1533 dwFlags - controls some details of the string copy:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1534
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1535 STRSAFE_FILL_BEHIND_NULL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1536 if the function succeeds, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1537 used to fill the uninitialize part of destination buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1538 behind the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1539
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1540 STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1541 treat NULL string pointers like empty strings (TEXT("")).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1542 this flag is useful for emulating functions like lstrcat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1543
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1544 STRSAFE_FILL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1545 if the function fails, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1546 used to fill all of the destination buffer, and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1547 be null terminated. This will overwrite any pre-existing
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1548 or truncated string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1549
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1550 STRSAFE_NULL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1551 if the function fails, the destination buffer will be set
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1552 to the empty string. This will overwrite any pre-existing or
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1553 truncated string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1554
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1555 STRSAFE_NO_TRUNCATION
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1556 if the function returns STRSAFE_E_INSUFFICIENT_BUFFER, pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1557 will not contain a truncated string, it will remain unchanged.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1558
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1559 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1560 Behavior is undefined if source and destination strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1561
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1562 pszDest and pszSrc should not be NULL unless the STRSAFE_IGNORE_NULLS flag
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1563 is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and pszSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1564 may be NULL. An error may still be returned even though NULLS are ignored
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1565 due to insufficient space.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1566
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1567 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1568
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1569 S_OK - if there was source data and it was all concatenated and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1570 the resultant dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1571
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1572 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1573 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1574
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1575 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1576 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1577 - this return value is an indication that the operation
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1578 failed due to insufficient space. When this error
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1579 occurs, the destination buffer is modified to contain
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1580 a truncated version of the ideal result and is null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1581 terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1582 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1583
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1584 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1585 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1586
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1587 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1588
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1589 STRSAFEAPI StringCchCatExA(char* pszDest, size_t cchDest, const char* pszSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1590 STRSAFEAPI StringCchCatExW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1591 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1592 #define StringCchCatEx StringCchCatExW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1593 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1594 #define StringCchCatEx StringCchCatExA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1595 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1596
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1597 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1598 STRSAFEAPI StringCchCatExA(char* pszDest, size_t cchDest, const char* pszSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1599 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1600 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1601
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1602 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1603 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1604 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1605 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1606 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1607 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1608 size_t cbDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1609
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1610 // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1611 cbDest = cchDest * sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1612
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1613 hr = StringCatExWorkerA(pszDest, cchDest, cbDest, pszSrc, ppszDestEnd, pcchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1614 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1615
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1616 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1617 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1618
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1619 STRSAFEAPI StringCchCatExW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1620 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1621 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1622
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1623 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1624 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1625 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1626 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1627 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1628 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1629 size_t cbDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1630
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1631 // safe to multiply cchDest * sizeof(wchar_t) since cchDest < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1632 cbDest = cchDest * sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1633
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1634 hr = StringCatExWorkerW(pszDest, cchDest, cbDest, pszSrc, ppszDestEnd, pcchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1635 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1636
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1637 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1638 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1639 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1640 #endif // !STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1641
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1642
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1643 #ifndef STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1644 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1645
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1646 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1647 StringCbCatEx(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1648 IN OUT LPTSTR pszDest OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1649 IN size_t cbDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1650 IN LPCTSTR pszSrc OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1651 OUT LPTSTR* ppszDestEnd OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1652 OUT size_t* pcbRemaining OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1653 IN DWORD dwFlags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1654 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1655
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1656 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1657
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1658 This routine is a safer version of the C built-in function 'strcat' with
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1659 some additional parameters. In addition to functionality provided by
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1660 StringCbCat, this routine also returns a pointer to the end of the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1661 destination string and the number of bytes left in the destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1662 including the null terminator. The flags parameter allows additional controls.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1663
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1664 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1665
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1666 pszDest - destination string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1667
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1668 cbDest - size of destination buffer in bytes.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1669 length must be ((_tcslen(pszDest) + _tcslen(pszSrc) + 1) * sizeof(TCHAR)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1670 to hold all of the combine string plus the null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1671 terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1672
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1673 pszSrc - source string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1674
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1675 ppszDestEnd - if ppszDestEnd is non-null, the function will return a
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1676 pointer to the end of the destination string. If the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1677 function appended any data, the result will point to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1678 null termination character
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1679
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1680 pcbRemaining - if pcbRemaining is non-null, the function will return
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1681 the number of bytes left in the destination string,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1682 including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1683
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1684 dwFlags - controls some details of the string copy:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1685
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1686 STRSAFE_FILL_BEHIND_NULL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1687 if the function succeeds, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1688 used to fill the uninitialize part of destination buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1689 behind the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1690
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1691 STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1692 treat NULL string pointers like empty strings (TEXT("")).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1693 this flag is useful for emulating functions like lstrcat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1694
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1695 STRSAFE_FILL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1696 if the function fails, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1697 used to fill all of the destination buffer, and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1698 be null terminated. This will overwrite any pre-existing
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1699 or truncated string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1700
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1701 STRSAFE_NULL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1702 if the function fails, the destination buffer will be set
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1703 to the empty string. This will overwrite any pre-existing or
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1704 truncated string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1705
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1706 STRSAFE_NO_TRUNCATION
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1707 if the function returns STRSAFE_E_INSUFFICIENT_BUFFER, pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1708 will not contain a truncated string, it will remain unchanged.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1709
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1710 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1711 Behavior is undefined if source and destination strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1712
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1713 pszDest and pszSrc should not be NULL unless the STRSAFE_IGNORE_NULLS flag
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1714 is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and pszSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1715 may be NULL. An error may still be returned even though NULLS are ignored
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1716 due to insufficient space.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1717
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1718 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1719
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1720 S_OK - if there was source data and it was all concatenated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1721 and the resultant dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1722
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1723 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1724 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1725
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1726 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1727 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1728 - this return value is an indication that the operation
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1729 failed due to insufficient space. When this error
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1730 occurs, the destination buffer is modified to contain
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1731 a truncated version of the ideal result and is null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1732 terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1733 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1734
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1735 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1736 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1737
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1738 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1739
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1740 STRSAFEAPI StringCbCatExA(char* pszDest, size_t cbDest, const char* pszSrc, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1741 STRSAFEAPI StringCbCatExW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1742 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1743 #define StringCbCatEx StringCbCatExW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1744 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1745 #define StringCbCatEx StringCbCatExA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1746 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1747
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1748 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1749 STRSAFEAPI StringCbCatExA(char* pszDest, size_t cbDest, const char* pszSrc, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1750 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1751 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1752 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1753 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1754
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1755 cchDest = cbDest / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1756
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1757 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1758 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1759 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1760 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1761 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1762 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1763 hr = StringCatExWorkerA(pszDest, cchDest, cbDest, pszSrc, ppszDestEnd, &cchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1764 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1765
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1766 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1767 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1768 if (pcbRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1769 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1770 // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1771 *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1772 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1773 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1774
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1775 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1776 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1777
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1778 STRSAFEAPI StringCbCatExW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1779 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1780 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1781 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1782 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1783
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1784 cchDest = cbDest / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1785
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1786 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1787 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1788 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1789 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1790 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1791 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1792 hr = StringCatExWorkerW(pszDest, cchDest, cbDest, pszSrc, ppszDestEnd, &cchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1793 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1794
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1795 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1796 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1797 if (pcbRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1798 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1799 // safe to multiply cchRemaining * sizeof(wchar_t) since cchRemaining < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1800 *pcbRemaining = (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1801 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1802 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1803
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1804 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1805 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1806 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1807 #endif // !STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1808
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1809
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1810 #ifndef STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1811 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1812
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1813 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1814 StringCchCatN(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1815 IN OUT LPTSTR pszDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1816 IN size_t cchDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1817 IN LPCTSTR pszSrc,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1818 IN size_t cchMaxAppend
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1819 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1820
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1821 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1822
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1823 This routine is a safer version of the C built-in function 'strncat'.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1824 The size of the destination buffer (in characters) is a parameter as well as
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1825 the maximum number of characters to append, excluding the null terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1826 This function will not write past the end of the destination buffer and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1827 ALWAYS null terminate pszDest (unless it is zero length).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1828
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1829 This function returns a hresult, and not a pointer. It returns
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1830 S_OK if all of pszSrc or the first cchMaxAppend characters were appended
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1831 to the destination string and it was null terminated, otherwise it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1832 return a failure code. In failure cases as much of pszSrc will be appended
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1833 to pszDest as possible, and pszDest will be null terminated.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1834
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1835 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1836
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1837 pszDest - destination string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1838
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1839 cchDest - size of destination buffer in characters.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1840 length must be (_tcslen(pszDest) + min(cchMaxAppend, _tcslen(pszSrc)) + 1)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1841 to hold all of the combine string plus the null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1842 terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1843
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1844 pszSrc - source string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1845
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1846 cchMaxAppend - maximum number of characters to append
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1847
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1848 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1849 Behavior is undefined if source and destination strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1850
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1851 pszDest and pszSrc should not be NULL. See StringCchCatNEx if you require
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1852 the handling of NULL values.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1853
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1854 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1855
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1856 S_OK - if all of pszSrc or the first cchMaxAppend characters
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1857 were concatenated to pszDest and the resultant dest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1858 string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1859
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1860 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1861 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1862
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1863 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1864 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1865 - this return value is an indication that the operation
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1866 failed due to insufficient space. When this error
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1867 occurs, the destination buffer is modified to contain
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1868 a truncated version of the ideal result and is null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1869 terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1870 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1871
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1872 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1873 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1874
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1875 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1876
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1877 STRSAFEAPI StringCchCatNA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchMaxAppend);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1878 STRSAFEAPI StringCchCatNW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchMaxAppend);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1879 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1880 #define StringCchCatN StringCchCatNW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1881 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1882 #define StringCchCatN StringCchCatNA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1883 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1884
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1885 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1886 STRSAFEAPI StringCchCatNA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchMaxAppend)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1887 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1888 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1889
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1890 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1891 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1892 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1893 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1894 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1895 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1896 hr = StringCatNWorkerA(pszDest, cchDest, pszSrc, cchMaxAppend);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1897 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1898
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1899 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1900 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1901
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1902 STRSAFEAPI StringCchCatNW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchMaxAppend)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1903 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1904 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1905
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1906 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1907 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1908 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1909 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1910 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1911 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1912 hr = StringCatNWorkerW(pszDest, cchDest, pszSrc, cchMaxAppend);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1913 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1914
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1915 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1916 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1917 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1918 #endif // !STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1919
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1920
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1921 #ifndef STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1922 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1923
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1924 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1925 StringCbCatN(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1926 IN OUT LPTSTR pszDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1927 IN size_t cbDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1928 IN LPCTSTR pszSrc,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1929 IN size_t cbMaxAppend
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1930 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1931
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1932 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1933
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1934 This routine is a safer version of the C built-in function 'strncat'.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1935 The size of the destination buffer (in bytes) is a parameter as well as
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1936 the maximum number of bytes to append, excluding the null terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1937 This function will not write past the end of the destination buffer and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1938 ALWAYS null terminate pszDest (unless it is zero length).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1939
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1940 This function returns a hresult, and not a pointer. It returns
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1941 S_OK if all of pszSrc or the first cbMaxAppend bytes were appended
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1942 to the destination string and it was null terminated, otherwise it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1943 return a failure code. In failure cases as much of pszSrc will be appended
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1944 to pszDest as possible, and pszDest will be null terminated.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1945
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1946 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1947
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1948 pszDest - destination string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1949
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1950 cbDest - size of destination buffer in bytes.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1951 length must be ((_tcslen(pszDest) + min(cbMaxAppend / sizeof(TCHAR), _tcslen(pszSrc)) + 1) * sizeof(TCHAR)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1952 to hold all of the combine string plus the null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1953 terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1954
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1955 pszSrc - source string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1956
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1957 cbMaxAppend - maximum number of bytes to append
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1958
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1959 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1960 Behavior is undefined if source and destination strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1961
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1962 pszDest and pszSrc should not be NULL. See StringCbCatNEx if you require
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1963 the handling of NULL values.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1964
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1965 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1966
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1967 S_OK - if all of pszSrc or the first cbMaxAppend bytes were
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1968 concatenated to pszDest and the resultant dest string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1969 was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1970
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1971 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1972 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1973
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1974 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1975 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1976 - this return value is an indication that the operation
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1977 failed due to insufficient space. When this error
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1978 occurs, the destination buffer is modified to contain
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1979 a truncated version of the ideal result and is null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1980 terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1981 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1982
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1983 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1984 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1985
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1986 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1987
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1988 STRSAFEAPI StringCbCatNA(char* pszDest, size_t cbDest, const char* pszSrc, size_t cbMaxAppend);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1989 STRSAFEAPI StringCbCatNW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, size_t cbMaxAppend);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1990 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1991 #define StringCbCatN StringCbCatNW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1992 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1993 #define StringCbCatN StringCbCatNA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1994 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1995
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1996 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1997 STRSAFEAPI StringCbCatNA(char* pszDest, size_t cbDest, const char* pszSrc, size_t cbMaxAppend)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1998 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
1999 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2000 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2001
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2002 cchDest = cbDest / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2003
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2004 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2005 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2006 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2007 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2008 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2009 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2010 size_t cchMaxAppend;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2011
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2012 cchMaxAppend = cbMaxAppend / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2013
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2014 hr = StringCatNWorkerA(pszDest, cchDest, pszSrc, cchMaxAppend);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2015 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2016
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2017 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2018 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2019
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2020 STRSAFEAPI StringCbCatNW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, size_t cbMaxAppend)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2021 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2022 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2023 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2024
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2025 cchDest = cbDest / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2026
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2027 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2028 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2029 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2030 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2031 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2032 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2033 size_t cchMaxAppend;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2034
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2035 cchMaxAppend = cbMaxAppend / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2036
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2037 hr = StringCatNWorkerW(pszDest, cchDest, pszSrc, cchMaxAppend);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2038 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2039
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2040 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2041 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2042 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2043 #endif // !STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2044
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2045
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2046 #ifndef STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2047 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2048
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2049 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2050 StringCchCatNEx(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2051 IN OUT LPTSTR pszDest OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2052 IN size_t cchDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2053 IN LPCTSTR pszSrc OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2054 IN size_t cchMaxAppend,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2055 OUT LPTSTR* ppszDestEnd OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2056 OUT size_t* pcchRemaining OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2057 IN DWORD dwFlags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2058 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2059
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2060 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2061
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2062 This routine is a safer version of the C built-in function 'strncat', with
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2063 some additional parameters. In addition to functionality provided by
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2064 StringCchCatN, this routine also returns a pointer to the end of the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2065 destination string and the number of characters left in the destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2066 including the null terminator. The flags parameter allows additional controls.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2067
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2068 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2069
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2070 pszDest - destination string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2071
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2072 cchDest - size of destination buffer in characters.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2073 length must be (_tcslen(pszDest) + min(cchMaxAppend, _tcslen(pszSrc)) + 1)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2074 to hold all of the combine string plus the null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2075 terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2076
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2077 pszSrc - source string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2078
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2079 cchMaxAppend - maximum number of characters to append
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2080
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2081 ppszDestEnd - if ppszDestEnd is non-null, the function will return a
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2082 pointer to the end of the destination string. If the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2083 function appended any data, the result will point to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2084 null termination character
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2085
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2086 pcchRemaining - if pcchRemaining is non-null, the function will return the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2087 number of characters left in the destination string,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2088 including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2089
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2090 dwFlags - controls some details of the string copy:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2091
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2092 STRSAFE_FILL_BEHIND_NULL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2093 if the function succeeds, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2094 used to fill the uninitialize part of destination buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2095 behind the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2096
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2097 STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2098 treat NULL string pointers like empty strings (TEXT(""))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2099
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2100 STRSAFE_FILL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2101 if the function fails, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2102 used to fill all of the destination buffer, and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2103 be null terminated. This will overwrite any pre-existing
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2104 or truncated string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2105
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2106 STRSAFE_NULL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2107 if the function fails, the destination buffer will be set
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2108 to the empty string. This will overwrite any pre-existing or
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2109 truncated string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2110
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2111 STRSAFE_NO_TRUNCATION
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2112 if the function returns STRSAFE_E_INSUFFICIENT_BUFFER, pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2113 will not contain a truncated string, it will remain unchanged.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2114
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2115 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2116 Behavior is undefined if source and destination strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2117
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2118 pszDest and pszSrc should not be NULL unless the STRSAFE_IGNORE_NULLS flag
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2119 is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and pszSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2120 may be NULL. An error may still be returned even though NULLS are ignored
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2121 due to insufficient space.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2122
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2123 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2124
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2125 S_OK - if all of pszSrc or the first cchMaxAppend characters
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2126 were concatenated to pszDest and the resultant dest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2127 string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2128
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2129 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2130 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2131
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2132 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2133 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2134 - this return value is an indication that the operation
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2135 failed due to insufficient space. When this error
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2136 occurs, the destination buffer is modified to contain
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2137 a truncated version of the ideal result and is null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2138 terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2139 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2140
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2141 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2142 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2143
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2144 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2145
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2146 STRSAFEAPI StringCchCatNExA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchMaxAppend, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2147 STRSAFEAPI StringCchCatNExW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchMaxAppend, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2148 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2149 #define StringCchCatNEx StringCchCatNExW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2150 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2151 #define StringCchCatNEx StringCchCatNExA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2152 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2153
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2154 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2155 STRSAFEAPI StringCchCatNExA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchMaxAppend, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2156 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2157 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2158
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2159 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2160 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2161 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2162 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2163 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2164 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2165 size_t cbDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2166
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2167 // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2168 cbDest = cchDest * sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2169
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2170 hr = StringCatNExWorkerA(pszDest, cchDest, cbDest, pszSrc, cchMaxAppend, ppszDestEnd, pcchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2171 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2172
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2173 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2174 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2175
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2176 STRSAFEAPI StringCchCatNExW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchMaxAppend, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2177 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2178 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2179
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2180 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2181 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2182 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2183 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2184 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2185 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2186 size_t cbDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2187
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2188 // safe to multiply cchDest * sizeof(wchar_t) since cchDest < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2189 cbDest = cchDest * sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2190
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2191 hr = StringCatNExWorkerW(pszDest, cchDest, cbDest, pszSrc, cchMaxAppend, ppszDestEnd, pcchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2192 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2193
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2194 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2195 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2196 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2197 #endif // !STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2198
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2199
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2200 #ifndef STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2201 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2202
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2203 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2204 StringCbCatNEx(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2205 IN OUT LPTSTR pszDest OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2206 IN size_t cbDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2207 IN LPCTSTR pszSrc OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2208 IN size_t cbMaxAppend,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2209 OUT LPTSTR* ppszDestEnd OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2210 OUT size_t* pcchRemaining OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2211 IN DWORD dwFlags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2212 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2213
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2214 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2215
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2216 This routine is a safer version of the C built-in function 'strncat', with
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2217 some additional parameters. In addition to functionality provided by
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2218 StringCbCatN, this routine also returns a pointer to the end of the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2219 destination string and the number of bytes left in the destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2220 including the null terminator. The flags parameter allows additional controls.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2221
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2222 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2223
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2224 pszDest - destination string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2225
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2226 cbDest - size of destination buffer in bytes.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2227 length must be ((_tcslen(pszDest) + min(cbMaxAppend / sizeof(TCHAR), _tcslen(pszSrc)) + 1) * sizeof(TCHAR)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2228 to hold all of the combine string plus the null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2229 terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2230
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2231 pszSrc - source string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2232
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2233 cbMaxAppend - maximum number of bytes to append
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2234
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2235 ppszDestEnd - if ppszDestEnd is non-null, the function will return a
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2236 pointer to the end of the destination string. If the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2237 function appended any data, the result will point to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2238 null termination character
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2239
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2240 pcbRemaining - if pcbRemaining is non-null, the function will return the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2241 number of bytes left in the destination string,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2242 including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2243
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2244 dwFlags - controls some details of the string copy:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2245
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2246 STRSAFE_FILL_BEHIND_NULL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2247 if the function succeeds, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2248 used to fill the uninitialize part of destination buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2249 behind the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2250
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2251 STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2252 treat NULL string pointers like empty strings (TEXT(""))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2253
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2254 STRSAFE_FILL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2255 if the function fails, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2256 used to fill all of the destination buffer, and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2257 be null terminated. This will overwrite any pre-existing
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2258 or truncated string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2259
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2260 STRSAFE_NULL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2261 if the function fails, the destination buffer will be set
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2262 to the empty string. This will overwrite any pre-existing or
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2263 truncated string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2264
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2265 STRSAFE_NO_TRUNCATION
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2266 if the function returns STRSAFE_E_INSUFFICIENT_BUFFER, pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2267 will not contain a truncated string, it will remain unchanged.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2268
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2269 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2270 Behavior is undefined if source and destination strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2271
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2272 pszDest and pszSrc should not be NULL unless the STRSAFE_IGNORE_NULLS flag
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2273 is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and pszSrc
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2274 may be NULL. An error may still be returned even though NULLS are ignored
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2275 due to insufficient space.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2276
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2277 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2278
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2279 S_OK - if all of pszSrc or the first cbMaxAppend bytes were
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2280 concatenated to pszDest and the resultant dest string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2281 was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2282
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2283 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2284 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2285
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2286 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2287 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2288 - this return value is an indication that the operation
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2289 failed due to insufficient space. When this error
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2290 occurs, the destination buffer is modified to contain
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2291 a truncated version of the ideal result and is null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2292 terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2293 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2294
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2295 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2296 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2297
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2298 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2299
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2300 STRSAFEAPI StringCbCatNExA(char* pszDest, size_t cbDest, const char* pszSrc, size_t cbMaxAppend, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2301 STRSAFEAPI StringCbCatNExW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, size_t cbMaxAppend, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2302 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2303 #define StringCbCatNEx StringCbCatNExW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2304 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2305 #define StringCbCatNEx StringCbCatNExA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2306 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2307
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2308 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2309 STRSAFEAPI StringCbCatNExA(char* pszDest, size_t cbDest, const char* pszSrc, size_t cbMaxAppend, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2310 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2311 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2312 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2313 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2314
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2315 cchDest = cbDest / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2316
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2317 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2318 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2319 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2320 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2321 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2322 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2323 size_t cchMaxAppend;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2324
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2325 cchMaxAppend = cbMaxAppend / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2326
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2327 hr = StringCatNExWorkerA(pszDest, cchDest, cbDest, pszSrc, cchMaxAppend, ppszDestEnd, &cchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2328 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2329
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2330 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2331 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2332 if (pcbRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2333 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2334 // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2335 *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2336 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2337 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2338
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2339 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2340 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2341
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2342 STRSAFEAPI StringCbCatNExW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszSrc, size_t cbMaxAppend, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2343 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2344 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2345 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2346 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2347
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2348 cchDest = cbDest / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2349
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2350 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2351 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2352 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2353 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2354 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2355 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2356 size_t cchMaxAppend;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2357
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2358 cchMaxAppend = cbMaxAppend / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2359
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2360 hr = StringCatNExWorkerW(pszDest, cchDest, cbDest, pszSrc, cchMaxAppend, ppszDestEnd, &cchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2361 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2362
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2363 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2364 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2365 if (pcbRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2366 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2367 // safe to multiply cchRemaining * sizeof(wchar_t) since cchRemaining < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2368 *pcbRemaining = (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2369 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2370 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2371
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2372 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2373 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2374 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2375 #endif // !STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2376
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2377
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2378 #ifndef STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2379 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2380
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2381 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2382 StringCchVPrintf(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2383 OUT LPTSTR pszDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2384 IN size_t cchDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2385 IN LPCTSTR pszFormat,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2386 IN va_list argList
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2387 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2388
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2389 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2390
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2391 This routine is a safer version of the C built-in function 'vsprintf'.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2392 The size of the destination buffer (in characters) is a parameter and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2393 this function will not write past the end of this buffer and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2394 ALWAYS null terminate the destination buffer (unless it is zero length).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2395
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2396 This function returns a hresult, and not a pointer. It returns
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2397 S_OK if the string was printed without truncation and null terminated,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2398 otherwise it will return a failure code. In failure cases it will return
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2399 a truncated version of the ideal result.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2400
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2401 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2402
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2403 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2404
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2405 cchDest - size of destination buffer in characters
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2406 length must be sufficient to hold the resulting formatted
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2407 string, including the null terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2408
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2409 pszFormat - format string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2410
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2411 argList - va_list from the variable arguments according to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2412 stdarg.h convention
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2413
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2414 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2415 Behavior is undefined if destination, format strings or any arguments
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2416 strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2417
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2418 pszDest and pszFormat should not be NULL. See StringCchVPrintfEx if you
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2419 require the handling of NULL values.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2420
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2421 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2422
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2423 S_OK - if there was sufficient space in the dest buffer for
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2424 the resultant string and it was null terminated.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2425
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2426 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2427 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2428
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2429 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2430 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2431 - this return value is an indication that the print
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2432 operation failed due to insufficient space. When this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2433 error occurs, the destination buffer is modified to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2434 contain a truncated version of the ideal result and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2435 null terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2436 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2437
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2438 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2439 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2440
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2441 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2442
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2443 STRSAFEAPI StringCchVPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2444 STRSAFEAPI StringCchVPrintfW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszFormat, va_list argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2445 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2446 #define StringCchVPrintf StringCchVPrintfW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2447 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2448 #define StringCchVPrintf StringCchVPrintfA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2449 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2450
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2451 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2452 STRSAFEAPI StringCchVPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2453 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2454 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2455
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2456 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2457 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2458 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2459 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2460 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2461 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2462 hr = StringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2463 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2464
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2465 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2466 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2467
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2468 STRSAFEAPI StringCchVPrintfW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszFormat, va_list argList)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2469 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2470 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2471
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2472 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2473 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2474 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2475 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2476 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2477 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2478 hr = StringVPrintfWorkerW(pszDest, cchDest, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2479 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2480
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2481 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2482 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2483 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2484 #endif // !STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2485
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2486
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2487 #ifndef STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2488 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2489
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2490 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2491 StringCbVPrintf(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2492 OUT LPTSTR pszDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2493 IN size_t cbDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2494 IN LPCTSTR pszFormat,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2495 IN va_list argList
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2496 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2497
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2498 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2499
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2500 This routine is a safer version of the C built-in function 'vsprintf'.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2501 The size of the destination buffer (in bytes) is a parameter and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2502 this function will not write past the end of this buffer and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2503 ALWAYS null terminate the destination buffer (unless it is zero length).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2504
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2505 This function returns a hresult, and not a pointer. It returns
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2506 S_OK if the string was printed without truncation and null terminated,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2507 otherwise it will return a failure code. In failure cases it will return
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2508 a truncated version of the ideal result.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2509
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2510 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2511
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2512 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2513
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2514 cbDest - size of destination buffer in bytes
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2515 length must be sufficient to hold the resulting formatted
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2516 string, including the null terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2517
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2518 pszFormat - format string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2519
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2520 argList - va_list from the variable arguments according to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2521 stdarg.h convention
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2522
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2523 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2524 Behavior is undefined if destination, format strings or any arguments
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2525 strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2526
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2527 pszDest and pszFormat should not be NULL. See StringCbVPrintfEx if you
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2528 require the handling of NULL values.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2529
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2530
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2531 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2532
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2533 S_OK - if there was sufficient space in the dest buffer for
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2534 the resultant string and it was null terminated.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2535
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2536 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2537 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2538
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2539 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2540 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2541 - this return value is an indication that the print
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2542 operation failed due to insufficient space. When this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2543 error occurs, the destination buffer is modified to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2544 contain a truncated version of the ideal result and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2545 null terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2546 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2547
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2548 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2549 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2550
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2551 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2552
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2553 STRSAFEAPI StringCbVPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, va_list argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2554 STRSAFEAPI StringCbVPrintfW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszFormat, va_list argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2555 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2556 #define StringCbVPrintf StringCbVPrintfW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2557 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2558 #define StringCbVPrintf StringCbVPrintfA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2559 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2560
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2561 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2562 STRSAFEAPI StringCbVPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, va_list argList)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2563 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2564 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2565 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2566
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2567 cchDest = cbDest / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2568
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2569 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2570 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2571 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2572 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2573 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2574 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2575 hr = StringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2576 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2577
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2578 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2579 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2580
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2581 STRSAFEAPI StringCbVPrintfW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszFormat, va_list argList)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2582 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2583 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2584 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2585
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2586 cchDest = cbDest / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2587
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2588 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2589 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2590 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2591 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2592 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2593 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2594 hr = StringVPrintfWorkerW(pszDest, cchDest, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2595 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2596
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2597 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2598 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2599 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2600 #endif // !STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2601
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2602
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2603 #ifndef STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2604 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2605
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2606 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2607 StringCchPrintf(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2608 OUT LPTSTR pszDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2609 IN size_t cchDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2610 IN LPCTSTR pszFormat,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2611 ...
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2612 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2613
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2614 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2615
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2616 This routine is a safer version of the C built-in function 'sprintf'.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2617 The size of the destination buffer (in characters) is a parameter and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2618 this function will not write past the end of this buffer and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2619 ALWAYS null terminate the destination buffer (unless it is zero length).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2620
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2621 This function returns a hresult, and not a pointer. It returns
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2622 S_OK if the string was printed without truncation and null terminated,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2623 otherwise it will return a failure code. In failure cases it will return
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2624 a truncated version of the ideal result.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2625
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2626 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2627
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2628 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2629
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2630 cchDest - size of destination buffer in characters
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2631 length must be sufficient to hold the resulting formatted
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2632 string, including the null terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2633
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2634 pszFormat - format string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2635
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2636 ... - additional parameters to be formatted according to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2637 the format string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2638
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2639 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2640 Behavior is undefined if destination, format strings or any arguments
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2641 strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2642
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2643 pszDest and pszFormat should not be NULL. See StringCchPrintfEx if you
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2644 require the handling of NULL values.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2645
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2646 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2647
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2648 S_OK - if there was sufficient space in the dest buffer for
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2649 the resultant string and it was null terminated.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2650
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2651 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2652 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2653
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2654 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2655 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2656 - this return value is an indication that the print
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2657 operation failed due to insufficient space. When this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2658 error occurs, the destination buffer is modified to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2659 contain a truncated version of the ideal result and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2660 null terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2661 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2662
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2663 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2664 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2665
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2666 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2667
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2668 STRSAFEAPI StringCchPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, ...);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2669 STRSAFEAPI StringCchPrintfW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszFormat, ...);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2670 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2671 #define StringCchPrintf StringCchPrintfW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2672 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2673 #define StringCchPrintf StringCchPrintfA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2674 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2675
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2676 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2677 STRSAFEAPI StringCchPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, ...)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2678 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2679 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2680
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2681 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2682 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2683 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2684 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2685 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2686 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2687 va_list argList;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2688
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2689 va_start(argList, pszFormat);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2690
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2691 hr = StringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2692
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2693 va_end(argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2694 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2695
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2696 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2697 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2698
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2699 STRSAFEAPI StringCchPrintfW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszFormat, ...)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2700 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2701 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2702
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2703 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2704 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2705 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2706 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2707 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2708 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2709 va_list argList;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2710
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2711 va_start(argList, pszFormat);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2712
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2713 hr = StringVPrintfWorkerW(pszDest, cchDest, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2714
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2715 va_end(argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2716 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2717
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2718 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2719 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2720 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2721 #endif // !STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2722
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2723
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2724 #ifndef STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2725 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2726
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2727 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2728 StringCbPrintf(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2729 OUT LPTSTR pszDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2730 IN size_t cbDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2731 IN LPCTSTR pszFormat,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2732 ...
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2733 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2734
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2735 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2736
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2737 This routine is a safer version of the C built-in function 'sprintf'.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2738 The size of the destination buffer (in bytes) is a parameter and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2739 this function will not write past the end of this buffer and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2740 ALWAYS null terminate the destination buffer (unless it is zero length).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2741
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2742 This function returns a hresult, and not a pointer. It returns
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2743 S_OK if the string was printed without truncation and null terminated,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2744 otherwise it will return a failure code. In failure cases it will return
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2745 a truncated version of the ideal result.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2746
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2747 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2748
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2749 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2750
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2751 cbDest - size of destination buffer in bytes
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2752 length must be sufficient to hold the resulting formatted
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2753 string, including the null terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2754
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2755 pszFormat - format string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2756
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2757 ... - additional parameters to be formatted according to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2758 the format string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2759
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2760 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2761 Behavior is undefined if destination, format strings or any arguments
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2762 strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2763
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2764 pszDest and pszFormat should not be NULL. See StringCbPrintfEx if you
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2765 require the handling of NULL values.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2766
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2767
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2768 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2769
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2770 S_OK - if there was sufficient space in the dest buffer for
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2771 the resultant string and it was null terminated.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2772
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2773 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2774 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2775
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2776 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2777 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2778 - this return value is an indication that the print
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2779 operation failed due to insufficient space. When this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2780 error occurs, the destination buffer is modified to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2781 contain a truncated version of the ideal result and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2782 null terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2783 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2784
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2785 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2786 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2787
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2788 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2789
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2790 STRSAFEAPI StringCbPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, ...);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2791 STRSAFEAPI StringCbPrintfW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszFormat, ...);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2792 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2793 #define StringCbPrintf StringCbPrintfW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2794 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2795 #define StringCbPrintf StringCbPrintfA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2796 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2797
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2798 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2799 STRSAFEAPI StringCbPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, ...)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2800 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2801 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2802 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2803
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2804 cchDest = cbDest / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2805
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2806 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2807 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2808 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2809 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2810 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2811 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2812 va_list argList;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2813
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2814 va_start(argList, pszFormat);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2815
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2816 hr = StringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2817
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2818 va_end(argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2819 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2820
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2821 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2822 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2823
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2824 STRSAFEAPI StringCbPrintfW(wchar_t* pszDest, size_t cbDest, const wchar_t* pszFormat, ...)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2825 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2826 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2827 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2828
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2829 cchDest = cbDest / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2830
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2831 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2832 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2833 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2834 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2835 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2836 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2837 va_list argList;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2838
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2839 va_start(argList, pszFormat);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2840
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2841 hr = StringVPrintfWorkerW(pszDest, cchDest, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2842
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2843 va_end(argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2844 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2845
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2846 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2847 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2848 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2849 #endif // !STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2850
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2851
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2852 #ifndef STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2853 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2854
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2855 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2856 StringCchPrintfEx(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2857 OUT LPTSTR pszDest OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2858 IN size_t cchDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2859 OUT LPTSTR* ppszDestEnd OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2860 OUT size_t* pcchRemaining OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2861 IN DWORD dwFlags,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2862 IN LPCTSTR pszFormat OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2863 ...
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2864 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2865
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2866 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2867
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2868 This routine is a safer version of the C built-in function 'sprintf' with
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2869 some additional parameters. In addition to functionality provided by
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2870 StringCchPrintf, this routine also returns a pointer to the end of the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2871 destination string and the number of characters left in the destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2872 including the null terminator. The flags parameter allows additional controls.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2873
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2874 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2875
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2876 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2877
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2878 cchDest - size of destination buffer in characters.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2879 length must be sufficient to contain the resulting
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2880 formatted string plus the null terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2881
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2882 ppszDestEnd - if ppszDestEnd is non-null, the function will return a
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2883 pointer to the end of the destination string. If the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2884 function printed any data, the result will point to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2885 null termination character
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2886
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2887 pcchRemaining - if pcchRemaining is non-null, the function will return
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2888 the number of characters left in the destination string,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2889 including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2890
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2891 dwFlags - controls some details of the string copy:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2892
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2893 STRSAFE_FILL_BEHIND_NULL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2894 if the function succeeds, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2895 used to fill the uninitialize part of destination buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2896 behind the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2897
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2898 STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2899 treat NULL string pointers like empty strings (TEXT(""))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2900
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2901 STRSAFE_FILL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2902 if the function fails, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2903 used to fill all of the destination buffer, and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2904 be null terminated. This will overwrite any truncated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2905 string returned when the failure is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2906 STRSAFE_E_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2907
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2908 STRSAFE_NO_TRUNCATION /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2909 STRSAFE_NULL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2910 if the function fails, the destination buffer will be set
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2911 to the empty string. This will overwrite any truncated string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2912 returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2913
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2914 pszFormat - format string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2915
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2916 ... - additional parameters to be formatted according to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2917 the format string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2918
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2919 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2920 Behavior is undefined if destination, format strings or any arguments
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2921 strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2922
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2923 pszDest and pszFormat should not be NULL unless the STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2924 flag is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2925 pszFormat may be NULL. An error may still be returned even though NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2926 are ignored due to insufficient space.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2927
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2928 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2929
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2930 S_OK - if there was source data and it was all concatenated and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2931 the resultant dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2932
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2933 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2934 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2935
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2936 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2937 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2938 - this return value is an indication that the print
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2939 operation failed due to insufficient space. When this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2940 error occurs, the destination buffer is modified to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2941 contain a truncated version of the ideal result and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2942 null terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2943 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2944
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2945 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2946 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2947
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2948 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2949
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2950 STRSAFEAPI StringCchPrintfExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, ...);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2951 STRSAFEAPI StringCchPrintfExW(wchar_t* pszDest, size_t cchDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const wchar_t* pszFormat, ...);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2952 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2953 #define StringCchPrintfEx StringCchPrintfExW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2954 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2955 #define StringCchPrintfEx StringCchPrintfExA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2956 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2957
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2958 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2959 STRSAFEAPI StringCchPrintfExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, ...)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2960 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2961 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2962
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2963 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2964 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2965 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2966 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2967 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2968 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2969 size_t cbDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2970 va_list argList;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2971
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2972 // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2973 cbDest = cchDest * sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2974 va_start(argList, pszFormat);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2975
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2976 hr = StringVPrintfExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2977
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2978 va_end(argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2979 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2980
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2981 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2982 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2983
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2984 STRSAFEAPI StringCchPrintfExW(wchar_t* pszDest, size_t cchDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const wchar_t* pszFormat, ...)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2985 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2986 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2987
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2988 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2989 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2990 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2991 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2992 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2993 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2994 size_t cbDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2995 va_list argList;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2996
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2997 // safe to multiply cchDest * sizeof(wchar_t) since cchDest < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2998 cbDest = cchDest * sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
2999 va_start(argList, pszFormat);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3000
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3001 hr = StringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3002
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3003 va_end(argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3004 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3005
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3006 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3007 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3008 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3009 #endif // !STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3010
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3011
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3012 #ifndef STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3013 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3014
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3015 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3016 StringCbPrintfEx(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3017 OUT LPTSTR pszDest OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3018 IN size_t cbDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3019 OUT LPTSTR* ppszDestEnd OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3020 OUT size_t* pcbRemaining OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3021 IN DWORD dwFlags,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3022 IN LPCTSTR pszFormat OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3023 ...
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3024 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3025
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3026 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3027
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3028 This routine is a safer version of the C built-in function 'sprintf' with
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3029 some additional parameters. In addition to functionality provided by
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3030 StringCbPrintf, this routine also returns a pointer to the end of the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3031 destination string and the number of bytes left in the destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3032 including the null terminator. The flags parameter allows additional controls.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3033
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3034 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3035
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3036 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3037
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3038 cbDest - size of destination buffer in bytes.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3039 length must be sufficient to contain the resulting
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3040 formatted string plus the null terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3041
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3042 ppszDestEnd - if ppszDestEnd is non-null, the function will return a
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3043 pointer to the end of the destination string. If the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3044 function printed any data, the result will point to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3045 null termination character
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3046
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3047 pcbRemaining - if pcbRemaining is non-null, the function will return
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3048 the number of bytes left in the destination string,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3049 including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3050
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3051 dwFlags - controls some details of the string copy:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3052
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3053 STRSAFE_FILL_BEHIND_NULL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3054 if the function succeeds, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3055 used to fill the uninitialize part of destination buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3056 behind the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3057
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3058 STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3059 treat NULL string pointers like empty strings (TEXT(""))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3060
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3061 STRSAFE_FILL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3062 if the function fails, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3063 used to fill all of the destination buffer, and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3064 be null terminated. This will overwrite any truncated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3065 string returned when the failure is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3066 STRSAFE_E_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3067
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3068 STRSAFE_NO_TRUNCATION /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3069 STRSAFE_NULL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3070 if the function fails, the destination buffer will be set
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3071 to the empty string. This will overwrite any truncated string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3072 returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3073
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3074 pszFormat - format string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3075
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3076 ... - additional parameters to be formatted according to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3077 the format string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3078
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3079 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3080 Behavior is undefined if destination, format strings or any arguments
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3081 strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3082
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3083 pszDest and pszFormat should not be NULL unless the STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3084 flag is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3085 pszFormat may be NULL. An error may still be returned even though NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3086 are ignored due to insufficient space.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3087
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3088 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3089
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3090 S_OK - if there was source data and it was all concatenated and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3091 the resultant dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3092
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3093 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3094 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3095
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3096 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3097 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3098 - this return value is an indication that the print
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3099 operation failed due to insufficient space. When this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3100 error occurs, the destination buffer is modified to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3101 contain a truncated version of the ideal result and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3102 null terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3103 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3104
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3105 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3106 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3107
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3108 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3109
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3110 STRSAFEAPI StringCbPrintfExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const char* pszFormat, ...);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3111 STRSAFEAPI StringCbPrintfExW(wchar_t* pszDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const wchar_t* pszFormat, ...);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3112 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3113 #define StringCbPrintfEx StringCbPrintfExW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3114 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3115 #define StringCbPrintfEx StringCbPrintfExA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3116 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3117
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3118 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3119 STRSAFEAPI StringCbPrintfExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const char* pszFormat, ...)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3120 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3121 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3122 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3123 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3124
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3125 cchDest = cbDest / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3126
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3127 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3128 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3129 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3130 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3131 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3132 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3133 va_list argList;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3134
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3135 va_start(argList, pszFormat);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3136
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3137 hr = StringVPrintfExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3138
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3139 va_end(argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3140 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3141
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3142 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3143 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3144 if (pcbRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3145 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3146 // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3147 *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3148 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3149 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3150
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3151 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3152 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3153
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3154 STRSAFEAPI StringCbPrintfExW(wchar_t* pszDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const wchar_t* pszFormat, ...)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3155 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3156 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3157 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3158 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3159
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3160 cchDest = cbDest / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3161
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3162 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3163 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3164 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3165 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3166 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3167 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3168 va_list argList;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3169
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3170 va_start(argList, pszFormat);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3171
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3172 hr = StringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3173
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3174 va_end(argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3175 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3176
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3177 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3178 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3179 if (pcbRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3180 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3181 // safe to multiply cchRemaining * sizeof(wchar_t) since cchRemaining < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3182 *pcbRemaining = (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3183 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3184 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3185
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3186 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3187 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3188 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3189 #endif // !STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3190
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3191
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3192 #ifndef STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3193 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3194
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3195 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3196 StringCchVPrintfEx(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3197 OUT LPTSTR pszDest OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3198 IN size_t cchDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3199 OUT LPTSTR* ppszDestEnd OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3200 OUT size_t* pcchRemaining OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3201 IN DWORD dwFlags,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3202 IN LPCTSTR pszFormat OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3203 IN va_list argList
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3204 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3205
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3206 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3207
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3208 This routine is a safer version of the C built-in function 'vsprintf' with
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3209 some additional parameters. In addition to functionality provided by
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3210 StringCchVPrintf, this routine also returns a pointer to the end of the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3211 destination string and the number of characters left in the destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3212 including the null terminator. The flags parameter allows additional controls.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3213
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3214 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3215
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3216 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3217
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3218 cchDest - size of destination buffer in characters.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3219 length must be sufficient to contain the resulting
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3220 formatted string plus the null terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3221
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3222 ppszDestEnd - if ppszDestEnd is non-null, the function will return a
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3223 pointer to the end of the destination string. If the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3224 function printed any data, the result will point to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3225 null termination character
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3226
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3227 pcchRemaining - if pcchRemaining is non-null, the function will return
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3228 the number of characters left in the destination string,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3229 including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3230
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3231 dwFlags - controls some details of the string copy:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3232
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3233 STRSAFE_FILL_BEHIND_NULL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3234 if the function succeeds, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3235 used to fill the uninitialize part of destination buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3236 behind the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3237
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3238 STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3239 treat NULL string pointers like empty strings (TEXT(""))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3240
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3241 STRSAFE_FILL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3242 if the function fails, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3243 used to fill all of the destination buffer, and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3244 be null terminated. This will overwrite any truncated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3245 string returned when the failure is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3246 STRSAFE_E_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3247
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3248 STRSAFE_NO_TRUNCATION /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3249 STRSAFE_NULL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3250 if the function fails, the destination buffer will be set
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3251 to the empty string. This will overwrite any truncated string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3252 returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3253
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3254 pszFormat - format string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3255
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3256 argList - va_list from the variable arguments according to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3257 stdarg.h convention
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3258
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3259 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3260 Behavior is undefined if destination, format strings or any arguments
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3261 strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3262
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3263 pszDest and pszFormat should not be NULL unless the STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3264 flag is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3265 pszFormat may be NULL. An error may still be returned even though NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3266 are ignored due to insufficient space.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3267
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3268 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3269
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3270 S_OK - if there was source data and it was all concatenated and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3271 the resultant dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3272
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3273 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3274 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3275
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3276 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3277 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3278 - this return value is an indication that the print
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3279 operation failed due to insufficient space. When this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3280 error occurs, the destination buffer is modified to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3281 contain a truncated version of the ideal result and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3282 null terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3283 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3284
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3285 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3286 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3287
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3288 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3289
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3290 STRSAFEAPI StringCchVPrintfExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3291 STRSAFEAPI StringCchVPrintfExW(wchar_t* pszDest, size_t cchDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const wchar_t* pszFormat, va_list argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3292 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3293 #define StringCchVPrintfEx StringCchVPrintfExW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3294 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3295 #define StringCchVPrintfEx StringCchVPrintfExA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3296 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3297
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3298 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3299 STRSAFEAPI StringCchVPrintfExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3300 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3301 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3302
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3303 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3304 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3305 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3306 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3307 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3308 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3309 size_t cbDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3310
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3311 // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3312 cbDest = cchDest * sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3313
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3314 hr = StringVPrintfExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3315 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3316
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3317 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3318 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3319
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3320 STRSAFEAPI StringCchVPrintfExW(wchar_t* pszDest, size_t cchDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const wchar_t* pszFormat, va_list argList)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3321 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3322 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3323
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3324 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3325 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3326 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3327 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3328 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3329 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3330 size_t cbDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3331
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3332 // safe to multiply cchDest * sizeof(wchar_t) since cchDest < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3333 cbDest = cchDest * sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3334
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3335 hr = StringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3336 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3337
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3338 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3339 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3340 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3341 #endif // !STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3342
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3343
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3344 #ifndef STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3345 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3346
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3347 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3348 StringCbVPrintfEx(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3349 OUT LPTSTR pszDest OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3350 IN size_t cbDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3351 OUT LPTSTR* ppszDestEnd OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3352 OUT size_t* pcbRemaining OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3353 IN DWORD dwFlags,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3354 IN LPCTSTR pszFormat OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3355 IN va_list argList
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3356 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3357
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3358 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3359
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3360 This routine is a safer version of the C built-in function 'vsprintf' with
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3361 some additional parameters. In addition to functionality provided by
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3362 StringCbVPrintf, this routine also returns a pointer to the end of the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3363 destination string and the number of characters left in the destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3364 including the null terminator. The flags parameter allows additional controls.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3365
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3366 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3367
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3368 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3369
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3370 cbDest - size of destination buffer in bytes.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3371 length must be sufficient to contain the resulting
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3372 formatted string plus the null terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3373
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3374 ppszDestEnd - if ppszDestEnd is non-null, the function will return
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3375 a pointer to the end of the destination string. If the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3376 function printed any data, the result will point to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3377 null termination character
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3378
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3379 pcbRemaining - if pcbRemaining is non-null, the function will return
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3380 the number of bytes left in the destination string,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3381 including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3382
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3383 dwFlags - controls some details of the string copy:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3384
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3385 STRSAFE_FILL_BEHIND_NULL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3386 if the function succeeds, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3387 used to fill the uninitialize part of destination buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3388 behind the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3389
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3390 STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3391 treat NULL string pointers like empty strings (TEXT(""))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3392
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3393 STRSAFE_FILL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3394 if the function fails, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3395 used to fill all of the destination buffer, and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3396 be null terminated. This will overwrite any truncated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3397 string returned when the failure is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3398 STRSAFE_E_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3399
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3400 STRSAFE_NO_TRUNCATION /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3401 STRSAFE_NULL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3402 if the function fails, the destination buffer will be set
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3403 to the empty string. This will overwrite any truncated string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3404 returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3405
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3406 pszFormat - format string which must be null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3407
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3408 argList - va_list from the variable arguments according to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3409 stdarg.h convention
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3410
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3411 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3412 Behavior is undefined if destination, format strings or any arguments
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3413 strings overlap.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3414
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3415 pszDest and pszFormat should not be NULL unless the STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3416 flag is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3417 pszFormat may be NULL. An error may still be returned even though NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3418 are ignored due to insufficient space.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3419
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3420 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3421
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3422 S_OK - if there was source data and it was all concatenated and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3423 the resultant dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3424
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3425 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3426 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3427
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3428 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3429 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3430 - this return value is an indication that the print
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3431 operation failed due to insufficient space. When this
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3432 error occurs, the destination buffer is modified to
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3433 contain a truncated version of the ideal result and is
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3434 null terminated. This is useful for situations where
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3435 truncation is ok.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3436
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3437 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3438 return value of this function
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3439
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3440 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3441
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3442 STRSAFEAPI StringCbVPrintfExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3443 STRSAFEAPI StringCbVPrintfExW(wchar_t* pszDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const wchar_t* pszFormat, va_list argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3444 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3445 #define StringCbVPrintfEx StringCbVPrintfExW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3446 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3447 #define StringCbVPrintfEx StringCbVPrintfExA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3448 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3449
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3450 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3451 STRSAFEAPI StringCbVPrintfExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3452 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3453 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3454 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3455 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3456
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3457 cchDest = cbDest / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3458
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3459 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3460 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3461 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3462 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3463 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3464 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3465 hr = StringVPrintfExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3466 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3467
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3468 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3469 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3470 if (pcbRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3471 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3472 // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3473 *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3474 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3475 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3476
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3477 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3478 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3479
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3480 STRSAFEAPI StringCbVPrintfExW(wchar_t* pszDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const wchar_t* pszFormat, va_list argList)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3481 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3482 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3483 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3484 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3485
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3486 cchDest = cbDest / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3487
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3488 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3489 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3490 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3491 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3492 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3493 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3494 hr = StringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3495 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3496
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3497 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3498 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3499 if (pcbRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3500 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3501 // safe to multiply cchRemaining * sizeof(wchar_t) since cchRemaining < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3502 *pcbRemaining = (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3503 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3504 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3505
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3506 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3507 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3508 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3509 #endif // !STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3510
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3511
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3512 #ifndef STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3513 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3514
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3515 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3516 StringCchGets(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3517 OUT LPTSTR pszDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3518 IN size_t cchDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3519 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3520
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3521 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3522
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3523 This routine is a safer version of the C built-in function 'gets'.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3524 The size of the destination buffer (in characters) is a parameter and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3525 this function will not write past the end of this buffer and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3526 ALWAYS null terminate the destination buffer (unless it is zero length).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3527
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3528 This routine is not a replacement for fgets. That function does not replace
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3529 newline characters with a null terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3530
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3531 This function returns a hresult, and not a pointer. It returns
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3532 S_OK if any characters were read from stdin and copied to pszDest and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3533 pszDest was null terminated, otherwise it will return a failure code.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3534
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3535 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3536
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3537 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3538
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3539 cchDest - size of destination buffer in characters.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3540
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3541 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3542 pszDest should not be NULL. See StringCchGetsEx if you require the handling
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3543 of NULL values.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3544
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3545 cchDest must be > 1 for this function to succeed.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3546
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3547 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3548
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3549 S_OK - data was read from stdin and copied, and the resultant
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3550 dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3551
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3552 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3553 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3554
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3555 STRSAFE_E_END_OF_FILE /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3556 HRESULT_CODE(hr) == ERROR_HANDLE_EOF
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3557 - this return value indicates an error or end-of-file
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3558 condition, use feof or ferror to determine which one has
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3559 occured.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3560
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3561 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3562 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3563 - this return value is an indication that there was
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3564 insufficient space in the destination buffer to copy any
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3565 data
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3566
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3567 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3568 return value of this function.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3569
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3570 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3571
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3572 #ifndef STRSAFE_LIB_IMPL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3573 STRSAFE_INLINE_API StringCchGetsA(char* pszDest, size_t cchDest);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3574 STRSAFE_INLINE_API StringCchGetsW(wchar_t* pszDest, size_t cchDest);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3575 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3576 #define StringCchGets StringCchGetsW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3577 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3578 #define StringCchGets StringCchGetsA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3579 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3580
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3581 STRSAFE_INLINE_API StringCchGetsA(char* pszDest, size_t cchDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3582 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3583 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3584
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3585 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3586 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3587 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3588 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3589 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3590 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3591 size_t cbDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3592
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3593 // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3594 cbDest = cchDest * sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3595
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3596 hr = StringGetsExWorkerA(pszDest, cchDest, cbDest, NULL, NULL, 0);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3597 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3598
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3599 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3600 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3601
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3602 STRSAFE_INLINE_API StringCchGetsW(wchar_t* pszDest, size_t cchDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3603 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3604 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3605
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3606 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3607 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3608 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3609 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3610 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3611 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3612 size_t cbDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3613
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3614 // safe to multiply cchDest * sizeof(wchar_t) since cchDest < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3615 cbDest = cchDest * sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3616
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3617 hr = StringGetsExWorkerW(pszDest, cchDest, cbDest, NULL, NULL, 0);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3618 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3619
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3620 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3621 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3622 #endif // !STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3623 #endif // !STRSAFE_LIB_IMPL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3624
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3625 #ifndef STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3626 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3627
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3628 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3629 StringCbGets(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3630 OUT LPTSTR pszDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3631 IN size_t cbDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3632 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3633
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3634 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3635
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3636 This routine is a safer version of the C built-in function 'gets'.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3637 The size of the destination buffer (in bytes) is a parameter and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3638 this function will not write past the end of this buffer and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3639 ALWAYS null terminate the destination buffer (unless it is zero length).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3640
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3641 This routine is not a replacement for fgets. That function does not replace
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3642 newline characters with a null terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3643
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3644 This function returns a hresult, and not a pointer. It returns
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3645 S_OK if any characters were read from stdin and copied to pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3646 and pszDest was null terminated, otherwise it will return a failure code.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3647
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3648 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3649
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3650 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3651
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3652 cbDest - size of destination buffer in bytes.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3653
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3654 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3655 pszDest should not be NULL. See StringCbGetsEx if you require the handling
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3656 of NULL values.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3657
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3658 cbDest must be > sizeof(TCHAR) for this function to succeed.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3659
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3660 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3661
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3662 S_OK - data was read from stdin and copied, and the resultant
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3663 dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3664
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3665 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3666 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3667
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3668 STRSAFE_E_END_OF_FILE /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3669 HRESULT_CODE(hr) == ERROR_HANDLE_EOF
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3670 - this return value indicates an error or end-of-file
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3671 condition, use feof or ferror to determine which one has
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3672 occured.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3673
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3674 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3675 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3676 - this return value is an indication that there was
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3677 insufficient space in the destination buffer to copy any
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3678 data
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3679
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3680 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3681 return value of this function.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3682
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3683 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3684
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3685 #ifndef STRSAFE_LIB_IMPL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3686 STRSAFE_INLINE_API StringCbGetsA(char* pszDest, size_t cbDest);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3687 STRSAFE_INLINE_API StringCbGetsW(wchar_t* pszDest, size_t cbDest);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3688 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3689 #define StringCbGets StringCbGetsW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3690 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3691 #define StringCbGets StringCbGetsA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3692 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3693
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3694 STRSAFE_INLINE_API StringCbGetsA(char* pszDest, size_t cbDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3695 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3696 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3697 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3698
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3699 // convert to count of characters
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3700 cchDest = cbDest / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3701
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3702 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3703 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3704 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3705 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3706 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3707 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3708 hr = StringGetsExWorkerA(pszDest, cchDest, cbDest, NULL, NULL, 0);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3709 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3710
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3711 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3712 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3713
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3714 STRSAFE_INLINE_API StringCbGetsW(wchar_t* pszDest, size_t cbDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3715 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3716 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3717 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3718
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3719 // convert to count of characters
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3720 cchDest = cbDest / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3721
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3722 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3723 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3724 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3725 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3726 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3727 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3728 hr = StringGetsExWorkerW(pszDest, cchDest, cbDest, NULL, NULL, 0);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3729 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3730
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3731 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3732 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3733 #endif // !STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3734 #endif // !STRSAFE_LIB_IMPL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3735
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3736 #ifndef STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3737 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3738
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3739 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3740 StringCchGetsEx(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3741 OUT LPTSTR pszDest OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3742 IN size_t cchDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3743 OUT LPTSTR* ppszDestEnd OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3744 OUT size_t* pcchRemaining OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3745 IN DWORD dwFlags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3746 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3747
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3748 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3749
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3750 This routine is a safer version of the C built-in function 'gets' with
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3751 some additional parameters. In addition to functionality provided by
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3752 StringCchGets, this routine also returns a pointer to the end of the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3753 destination string and the number of characters left in the destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3754 including the null terminator. The flags parameter allows additional controls.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3755
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3756 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3757
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3758 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3759
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3760 cchDest - size of destination buffer in characters.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3761
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3762 ppszDestEnd - if ppszDestEnd is non-null, the function will return a
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3763 pointer to the end of the destination string. If the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3764 function copied any data, the result will point to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3765 null termination character
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3766
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3767 pcchRemaining - if pcchRemaining is non-null, the function will return the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3768 number of characters left in the destination string,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3769 including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3770
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3771 dwFlags - controls some details of the string copy:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3772
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3773 STRSAFE_FILL_BEHIND_NULL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3774 if the function succeeds, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3775 used to fill the uninitialize part of destination buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3776 behind the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3777
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3778 STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3779 treat NULL string pointers like empty strings (TEXT("")).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3780
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3781 STRSAFE_FILL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3782 if the function fails, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3783 used to fill all of the destination buffer, and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3784 be null terminated.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3785
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3786 STRSAFE_NO_TRUNCATION /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3787 STRSAFE_NULL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3788 if the function fails, the destination buffer will be set
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3789 to the empty string.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3790
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3791 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3792 pszDest should not be NULL unless the STRSAFE_IGNORE_NULLS flag is specified.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3793 If STRSAFE_IGNORE_NULLS is passed and pszDest is NULL, an error may still be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3794 returned even though NULLS are ignored
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3795
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3796 cchDest must be > 1 for this function to succeed.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3797
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3798 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3799
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3800 S_OK - data was read from stdin and copied, and the resultant
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3801 dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3802
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3803 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3804 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3805
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3806 STRSAFE_E_END_OF_FILE /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3807 HRESULT_CODE(hr) == ERROR_HANDLE_EOF
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3808 - this return value indicates an error or end-of-file
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3809 condition, use feof or ferror to determine which one has
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3810 occured.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3811
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3812 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3813 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3814 - this return value is an indication that there was
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3815 insufficient space in the destination buffer to copy any
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3816 data
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3817
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3818 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3819 return value of this function.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3820
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3821 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3822
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3823 #ifndef STRSAFE_LIB_IMPL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3824 STRSAFE_INLINE_API StringCchGetsExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3825 STRSAFE_INLINE_API StringCchGetsExW(wchar_t* pszDest, size_t cchDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3826 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3827 #define StringCchGetsEx StringCchGetsExW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3828 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3829 #define StringCchGetsEx StringCchGetsExA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3830 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3831
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3832 STRSAFE_INLINE_API StringCchGetsExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3833 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3834 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3835
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3836 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3837 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3838 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3839 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3840 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3841 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3842 size_t cbDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3843
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3844 // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3845 cbDest = cchDest * sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3846
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3847 hr = StringGetsExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3848 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3849
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3850 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3851 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3852
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3853 STRSAFE_INLINE_API StringCchGetsExW(wchar_t* pszDest, size_t cchDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3854 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3855 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3856
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3857 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3858 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3859 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3860 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3861 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3862 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3863 size_t cbDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3864
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3865 // safe to multiply cchDest * sizeof(wchar_t) since cchDest < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3866 cbDest = cchDest * sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3867
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3868 hr = StringGetsExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3869 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3870
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3871 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3872 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3873 #endif // !STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3874 #endif // !STRSAFE_LIB_IMPL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3875
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3876 #ifndef STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3877 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3878
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3879 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3880 StringCbGetsEx(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3881 OUT LPTSTR pszDest OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3882 IN size_t cbDest,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3883 OUT LPTSTR* ppszDestEnd OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3884 OUT size_t* pcbRemaining OPTIONAL,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3885 IN DWORD dwFlags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3886 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3887
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3888 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3889
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3890 This routine is a safer version of the C built-in function 'gets' with
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3891 some additional parameters. In addition to functionality provided by
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3892 StringCbGets, this routine also returns a pointer to the end of the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3893 destination string and the number of characters left in the destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3894 including the null terminator. The flags parameter allows additional controls.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3895
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3896 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3897
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3898 pszDest - destination string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3899
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3900 cbDest - size of destination buffer in bytes.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3901
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3902 ppszDestEnd - if ppszDestEnd is non-null, the function will return a
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3903 pointer to the end of the destination string. If the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3904 function copied any data, the result will point to the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3905 null termination character
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3906
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3907 pcbRemaining - if pbRemaining is non-null, the function will return the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3908 number of bytes left in the destination string,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3909 including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3910
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3911 dwFlags - controls some details of the string copy:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3912
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3913 STRSAFE_FILL_BEHIND_NULL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3914 if the function succeeds, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3915 used to fill the uninitialize part of destination buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3916 behind the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3917
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3918 STRSAFE_IGNORE_NULLS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3919 treat NULL string pointers like empty strings (TEXT("")).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3920
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3921 STRSAFE_FILL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3922 if the function fails, the low byte of dwFlags will be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3923 used to fill all of the destination buffer, and it will
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3924 be null terminated.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3925
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3926 STRSAFE_NO_TRUNCATION /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3927 STRSAFE_NULL_ON_FAILURE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3928 if the function fails, the destination buffer will be set
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3929 to the empty string.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3930
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3931 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3932 pszDest should not be NULL unless the STRSAFE_IGNORE_NULLS flag is specified.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3933 If STRSAFE_IGNORE_NULLS is passed and pszDest is NULL, an error may still be
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3934 returned even though NULLS are ignored
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3935
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3936 cbDest must be > sizeof(TCHAR) for this function to succeed
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3937
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3938 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3939
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3940 S_OK - data was read from stdin and copied, and the resultant
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3941 dest string was null terminated
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3942
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3943 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3944 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3945
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3946 STRSAFE_E_END_OF_FILE /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3947 HRESULT_CODE(hr) == ERROR_HANDLE_EOF
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3948 - this return value indicates an error or end-of-file
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3949 condition, use feof or ferror to determine which one has
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3950 occured.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3951
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3952 STRSAFE_E_INSUFFICIENT_BUFFER /
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3953 HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3954 - this return value is an indication that there was
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3955 insufficient space in the destination buffer to copy any
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3956 data
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3957
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3958 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3959 return value of this function.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3960
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3961 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3962
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3963 #ifndef STRSAFE_LIB_IMPL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3964 STRSAFE_INLINE_API StringCbGetsExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pbRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3965 STRSAFE_INLINE_API StringCbGetsExW(wchar_t* pszDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3966 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3967 #define StringCbGetsEx StringCbGetsExW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3968 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3969 #define StringCbGetsEx StringCbGetsExA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3970 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3971
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3972 STRSAFE_INLINE_API StringCbGetsExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3973 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3974 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3975 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3976 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3977
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3978 cchDest = cbDest / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3979
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3980 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3981 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3982 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3983 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3984 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3985 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3986 hr = StringGetsExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3987 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3988
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3989 if (SUCCEEDED(hr) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3990 (hr == STRSAFE_E_INSUFFICIENT_BUFFER) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3991 (hr == STRSAFE_E_END_OF_FILE))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3992 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3993 if (pcbRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3994 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3995 // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3996 *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3997 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3998 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
3999
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4000 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4001 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4002
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4003 STRSAFE_INLINE_API StringCbGetsExW(wchar_t* pszDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4004 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4005 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4006 size_t cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4007 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4008
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4009 cchDest = cbDest / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4010
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4011 if (cchDest > STRSAFE_MAX_CCH)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4012 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4013 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4014 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4015 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4016 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4017 hr = StringGetsExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4018 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4019
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4020 if (SUCCEEDED(hr) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4021 (hr == STRSAFE_E_INSUFFICIENT_BUFFER) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4022 (hr == STRSAFE_E_END_OF_FILE))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4023 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4024 if (pcbRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4025 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4026 // safe to multiply cchRemaining * sizeof(wchar_t) since cchRemaining < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4027 *pcbRemaining = (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4028 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4029 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4030
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4031 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4032 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4033 #endif // !STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4034 #endif // !STRSAFE_LIB_IMPL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4035
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4036 #ifndef STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4037 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4038
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4039 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4040 StringCchLength(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4041 IN LPCTSTR psz,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4042 IN size_t cchMax,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4043 OUT size_t* pcch OPTIONAL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4044 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4045
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4046 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4047
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4048 This routine is a safer version of the C built-in function 'strlen'.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4049 It is used to make sure a string is not larger than a given length, and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4050 it optionally returns the current length in characters not including
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4051 the null terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4052
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4053 This function returns a hresult, and not a pointer. It returns
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4054 S_OK if the string is non-null and the length including the null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4055 terminator is less than or equal to cchMax characters.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4056
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4057 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4058
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4059 psz - string to check the length of
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4060
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4061 cchMax - maximum number of characters including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4062 that psz is allowed to contain
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4063
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4064 pcch - if the function succeeds and pcch is non-null, the current length
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4065 in characters of psz excluding the null terminator will be returned.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4066 This out parameter is equivalent to the return value of strlen(psz)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4067
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4068 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4069 psz can be null but the function will fail
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4070
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4071 cchMax should be greater than zero or the function will fail
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4072
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4073 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4074
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4075 S_OK - psz is non-null and the length including the null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4076 terminator is less than or equal to cchMax characters
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4077
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4078 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4079 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4080
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4081 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4082 return value of this function.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4083
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4084 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4085
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4086 STRSAFEAPI StringCchLengthA(const char* psz, size_t cchMax, size_t* pcch);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4087 STRSAFEAPI StringCchLengthW(const wchar_t* psz, size_t cchMax, size_t* pcch);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4088 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4089 #define StringCchLength StringCchLengthW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4090 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4091 #define StringCchLength StringCchLengthA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4092 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4093
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4094 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4095 STRSAFEAPI StringCchLengthA(const char* psz, size_t cchMax, size_t* pcch)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4096 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4097 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4098
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4099 if ((psz == NULL) || (cchMax > STRSAFE_MAX_CCH))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4100 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4101 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4102 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4103 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4104 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4105 hr = StringLengthWorkerA(psz, cchMax, pcch);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4106 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4107
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4108 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4109 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4110
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4111 STRSAFEAPI StringCchLengthW(const wchar_t* psz, size_t cchMax, size_t* pcch)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4112 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4113 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4114
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4115 if ((psz == NULL) || (cchMax > STRSAFE_MAX_CCH))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4116 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4117 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4118 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4119 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4120 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4121 hr = StringLengthWorkerW(psz, cchMax, pcch);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4122 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4123
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4124 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4125 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4126 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4127 #endif // !STRSAFE_NO_CCH_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4128
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4129
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4130 #ifndef STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4131 /*++
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4132
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4133 STDAPI
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4134 StringCbLength(
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4135 IN LPCTSTR psz,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4136 IN size_t cbMax,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4137 OUT size_t* pcb OPTIONAL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4138 );
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4139
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4140 Routine Description:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4141
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4142 This routine is a safer version of the C built-in function 'strlen'.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4143 It is used to make sure a string is not larger than a given length, and
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4144 it optionally returns the current length in bytes not including
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4145 the null terminator.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4146
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4147 This function returns a hresult, and not a pointer. It returns
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4148 S_OK if the string is non-null and the length including the null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4149 terminator is less than or equal to cbMax bytes.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4150
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4151 Arguments:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4152
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4153 psz - string to check the length of
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4154
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4155 cbMax - maximum number of bytes including the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4156 that psz is allowed to contain
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4157
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4158 pcb - if the function succeeds and pcb is non-null, the current length
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4159 in bytes of psz excluding the null terminator will be returned.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4160 This out parameter is equivalent to the return value of strlen(psz) * sizeof(TCHAR)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4161
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4162 Notes:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4163 psz can be null but the function will fail
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4164
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4165 cbMax should be greater than or equal to sizeof(TCHAR) or the function will fail
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4166
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4167 Return Value:
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4168
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4169 S_OK - psz is non-null and the length including the null
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4170 terminator is less than or equal to cbMax bytes
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4171
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4172 failure - you can use the macro HRESULT_CODE() to get a win32
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4173 error code for all hresult failure cases
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4174
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4175 It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4176 return value of this function.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4177
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4178 --*/
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4179
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4180 STRSAFEAPI StringCbLengthA(const char* psz, size_t cchMax, size_t* pcch);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4181 STRSAFEAPI StringCbLengthW(const wchar_t* psz, size_t cchMax, size_t* pcch);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4182 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4183 #define StringCbLength StringCbLengthW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4184 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4185 #define StringCbLength StringCbLengthA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4186 #endif // !UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4187
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4188 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4189 STRSAFEAPI StringCbLengthA(const char* psz, size_t cbMax, size_t* pcb)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4190 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4191 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4192 size_t cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4193 size_t cch = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4194
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4195 cchMax = cbMax / sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4196
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4197 if ((psz == NULL) || (cchMax > STRSAFE_MAX_CCH))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4198 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4199 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4200 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4201 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4202 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4203 hr = StringLengthWorkerA(psz, cchMax, &cch);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4204 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4205
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4206 if (SUCCEEDED(hr) && pcb)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4207 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4208 // safe to multiply cch * sizeof(char) since cch < STRSAFE_MAX_CCH and sizeof(char) is 1
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4209 *pcb = cch * sizeof(char);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4210 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4211
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4212 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4213 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4214
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4215 STRSAFEAPI StringCbLengthW(const wchar_t* psz, size_t cbMax, size_t* pcb)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4216 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4217 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4218 size_t cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4219 size_t cch = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4220
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4221 cchMax = cbMax / sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4222
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4223 if ((psz == NULL) || (cchMax > STRSAFE_MAX_CCH))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4224 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4225 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4226 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4227 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4228 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4229 hr = StringLengthWorkerW(psz, cchMax, &cch);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4230 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4231
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4232 if (SUCCEEDED(hr) && pcb)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4233 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4234 // safe to multiply cch * sizeof(wchar_t) since cch < STRSAFE_MAX_CCH and sizeof(wchar_t) is 2
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4235 *pcb = cch * sizeof(wchar_t);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4236 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4237
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4238 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4239 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4240 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4241 #endif // !STRSAFE_NO_CB_FUNCTIONS
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4242
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4243
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4244 // these are the worker functions that actually do the work
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4245 #ifdef STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4246 STRSAFEAPI StringCopyWorkerA(char* pszDest, size_t cchDest, const char* pszSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4247 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4248 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4249
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4250 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4251 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4252 // can not null terminate a zero-byte dest buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4253 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4254 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4255 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4256 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4257 while (cchDest && (*pszSrc != '\0'))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4258 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4259 *pszDest++ = *pszSrc++;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4260 cchDest--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4261 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4262
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4263 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4264 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4265 // we are going to truncate pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4266 pszDest--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4267 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4268 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4269
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4270 *pszDest= '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4271 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4272
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4273 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4274 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4275
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4276 STRSAFEAPI StringCopyWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4277 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4278 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4279
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4280 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4281 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4282 // can not null terminate a zero-byte dest buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4283 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4284 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4285 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4286 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4287 while (cchDest && (*pszSrc != L'\0'))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4288 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4289 *pszDest++ = *pszSrc++;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4290 cchDest--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4291 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4292
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4293 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4294 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4295 // we are going to truncate pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4296 pszDest--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4297 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4298 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4299
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4300 *pszDest= L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4301 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4302
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4303 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4304 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4305
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4306 STRSAFEAPI StringCopyExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4307 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4308 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4309 char* pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4310 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4311
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4312 // ASSERT(cbDest == (cchDest * sizeof(char)) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4313 // cbDest == (cchDest * sizeof(char)) + (cbDest % sizeof(char)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4314
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4315 // only accept valid flags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4316 if (dwFlags & (~STRSAFE_VALID_FLAGS))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4317 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4318 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4319 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4320 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4321 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4322 if (dwFlags & STRSAFE_IGNORE_NULLS)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4323 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4324 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4325 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4326 if ((cchDest != 0) || (cbDest != 0))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4327 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4328 // NULL pszDest and non-zero cchDest/cbDest is invalid
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4329 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4330 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4331 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4332
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4333 if (pszSrc == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4334 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4335 pszSrc = "";
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4336 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4337 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4338
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4339 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4340 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4341 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4342 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4343 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4344 cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4345
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4346 // only fail if there was actually src data to copy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4347 if (*pszSrc != '\0')
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4348 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4349 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4350 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4351 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4352 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4353 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4354 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4355 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4356 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4357 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4358 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4359 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4360 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4361 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4362 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4363
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4364 while (cchRemaining && (*pszSrc != '\0'))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4365 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4366 *pszDestEnd++= *pszSrc++;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4367 cchRemaining--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4368 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4369
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4370 if (cchRemaining > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4371 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4372 if (dwFlags & STRSAFE_FILL_BEHIND_NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4373 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4374 memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(char)) + (cbDest % sizeof(char)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4375 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4376 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4377 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4378 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4379 // we are going to truncate pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4380 pszDestEnd--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4381 cchRemaining++;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4382
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4383 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4384 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4385
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4386 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4387 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4388 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4389 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4390
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4391 if (FAILED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4392 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4393 if (pszDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4394 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4395 if (dwFlags & STRSAFE_FILL_ON_FAILURE)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4396 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4397 memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4398
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4399 if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4400 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4401 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4402 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4403 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4404 else if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4405 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4406 pszDestEnd = pszDest + cchDest - 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4407 cchRemaining = 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4408
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4409 // null terminate the end of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4410 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4411 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4412 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4413
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4414 if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4415 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4416 if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4417 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4418 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4419 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4420
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4421 // null terminate the beginning of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4422 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4423 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4424 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4425 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4426 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4427
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4428 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4429 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4430 if (ppszDestEnd)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4431 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4432 *ppszDestEnd = pszDestEnd;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4433 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4434
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4435 if (pcchRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4436 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4437 *pcchRemaining = cchRemaining;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4438 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4439 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4440
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4441 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4442 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4443
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4444 STRSAFEAPI StringCopyExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4445 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4446 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4447 wchar_t* pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4448 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4449
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4450 // ASSERT(cbDest == (cchDest * sizeof(wchar_t)) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4451 // cbDest == (cchDest * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4452
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4453 // only accept valid flags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4454 if (dwFlags & (~STRSAFE_VALID_FLAGS))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4455 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4456 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4457 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4458 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4459 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4460 if (dwFlags & STRSAFE_IGNORE_NULLS)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4461 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4462 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4463 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4464 if ((cchDest != 0) || (cbDest != 0))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4465 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4466 // NULL pszDest and non-zero cchDest/cbDest is invalid
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4467 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4468 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4469 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4470
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4471 if (pszSrc == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4472 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4473 pszSrc = L"";
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4474 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4475 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4476
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4477 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4478 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4479 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4480 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4481 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4482 cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4483
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4484 // only fail if there was actually src data to copy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4485 if (*pszSrc != L'\0')
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4486 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4487 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4488 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4489 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4490 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4491 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4492 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4493 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4494 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4495 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4496 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4497 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4498 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4499 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4500 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4501
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4502 while (cchRemaining && (*pszSrc != L'\0'))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4503 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4504 *pszDestEnd++= *pszSrc++;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4505 cchRemaining--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4506 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4507
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4508 if (cchRemaining > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4509 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4510 if (dwFlags & STRSAFE_FILL_BEHIND_NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4511 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4512 memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4513 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4514 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4515 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4516 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4517 // we are going to truncate pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4518 pszDestEnd--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4519 cchRemaining++;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4520
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4521 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4522 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4523
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4524 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4525 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4526 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4527 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4528
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4529 if (FAILED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4530 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4531 if (pszDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4532 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4533 if (dwFlags & STRSAFE_FILL_ON_FAILURE)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4534 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4535 memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4536
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4537 if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4538 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4539 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4540 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4541 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4542 else if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4543 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4544 pszDestEnd = pszDest + cchDest - 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4545 cchRemaining = 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4546
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4547 // null terminate the end of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4548 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4549 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4550 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4551
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4552 if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4553 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4554 if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4555 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4556 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4557 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4558
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4559 // null terminate the beginning of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4560 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4561 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4562 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4563 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4564 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4565
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4566 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4567 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4568 if (ppszDestEnd)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4569 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4570 *ppszDestEnd = pszDestEnd;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4571 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4572
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4573 if (pcchRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4574 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4575 *pcchRemaining = cchRemaining;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4576 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4577 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4578
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4579 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4580 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4581
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4582 STRSAFEAPI StringCopyNWorkerA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4583 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4584 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4585
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4586 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4587 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4588 // can not null terminate a zero-byte dest buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4589 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4590 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4591 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4592 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4593 while (cchDest && cchSrc && (*pszSrc != '\0'))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4594 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4595 *pszDest++= *pszSrc++;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4596 cchDest--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4597 cchSrc--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4598 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4599
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4600 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4601 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4602 // we are going to truncate pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4603 pszDest--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4604 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4605 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4606
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4607 *pszDest= '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4608 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4609
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4610 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4611 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4612
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4613 STRSAFEAPI StringCopyNWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4614 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4615 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4616
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4617 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4618 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4619 // can not null terminate a zero-byte dest buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4620 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4621 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4622 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4623 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4624 while (cchDest && cchSrc && (*pszSrc != L'\0'))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4625 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4626 *pszDest++= *pszSrc++;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4627 cchDest--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4628 cchSrc--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4629 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4630
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4631 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4632 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4633 // we are going to truncate pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4634 pszDest--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4635 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4636 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4637
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4638 *pszDest= L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4639 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4640
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4641 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4642 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4643
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4644 STRSAFEAPI StringCopyNExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, size_t cchSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4645 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4646 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4647 char* pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4648 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4649
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4650 // ASSERT(cbDest == (cchDest * sizeof(char)) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4651 // cbDest == (cchDest * sizeof(char)) + (cbDest % sizeof(char)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4652
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4653 // only accept valid flags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4654 if (dwFlags & (~STRSAFE_VALID_FLAGS))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4655 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4656 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4657 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4658 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4659 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4660 if (dwFlags & STRSAFE_IGNORE_NULLS)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4661 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4662 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4663 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4664 if ((cchDest != 0) || (cbDest != 0))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4665 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4666 // NULL pszDest and non-zero cchDest/cbDest is invalid
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4667 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4668 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4669 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4670
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4671 if (pszSrc == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4672 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4673 pszSrc = "";
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4674 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4675 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4676
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4677 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4678 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4679 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4680 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4681 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4682 cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4683
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4684 // only fail if there was actually src data to copy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4685 if (*pszSrc != '\0')
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4686 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4687 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4688 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4689 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4690 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4691 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4692 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4693 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4694 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4695 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4696 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4697 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4698 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4699 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4700 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4701
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4702 while (cchRemaining && cchSrc && (*pszSrc != '\0'))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4703 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4704 *pszDestEnd++= *pszSrc++;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4705 cchRemaining--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4706 cchSrc--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4707 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4708
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4709 if (cchRemaining > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4710 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4711 if (dwFlags & STRSAFE_FILL_BEHIND_NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4712 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4713 memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(char)) + (cbDest % sizeof(char)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4714 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4715 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4716 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4717 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4718 // we are going to truncate pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4719 pszDestEnd--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4720 cchRemaining++;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4721
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4722 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4723 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4724
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4725 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4726 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4727 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4728 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4729
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4730 if (FAILED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4731 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4732 if (pszDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4733 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4734 if (dwFlags & STRSAFE_FILL_ON_FAILURE)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4735 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4736 memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4737
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4738 if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4739 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4740 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4741 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4742 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4743 else if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4744 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4745 pszDestEnd = pszDest + cchDest - 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4746 cchRemaining = 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4747
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4748 // null terminate the end of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4749 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4750 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4751 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4752
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4753 if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4754 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4755 if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4756 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4757 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4758 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4759
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4760 // null terminate the beginning of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4761 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4762 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4763 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4764 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4765 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4766
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4767 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4768 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4769 if (ppszDestEnd)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4770 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4771 *ppszDestEnd = pszDestEnd;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4772 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4773
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4774 if (pcchRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4775 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4776 *pcchRemaining = cchRemaining;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4777 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4778 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4779
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4780 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4781 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4782
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4783 STRSAFEAPI StringCopyNExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, const wchar_t* pszSrc, size_t cchSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4784 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4785 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4786 wchar_t* pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4787 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4788
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4789 // ASSERT(cbDest == (cchDest * sizeof(wchar_t)) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4790 // cbDest == (cchDest * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4791
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4792 // only accept valid flags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4793 if (dwFlags & (~STRSAFE_VALID_FLAGS))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4794 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4795 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4796 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4797 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4798 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4799 if (dwFlags & STRSAFE_IGNORE_NULLS)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4800 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4801 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4802 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4803 if ((cchDest != 0) || (cbDest != 0))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4804 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4805 // NULL pszDest and non-zero cchDest/cbDest is invalid
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4806 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4807 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4808 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4809
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4810 if (pszSrc == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4811 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4812 pszSrc = L"";
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4813 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4814 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4815
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4816 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4817 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4818 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4819 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4820 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4821 cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4822
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4823 // only fail if there was actually src data to copy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4824 if (*pszSrc != L'\0')
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4825 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4826 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4827 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4828 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4829 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4830 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4831 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4832 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4833 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4834 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4835 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4836 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4837 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4838 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4839 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4840
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4841 while (cchRemaining && cchSrc && (*pszSrc != L'\0'))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4842 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4843 *pszDestEnd++= *pszSrc++;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4844 cchRemaining--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4845 cchSrc--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4846 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4847
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4848 if (cchRemaining > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4849 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4850 if (dwFlags & STRSAFE_FILL_BEHIND_NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4851 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4852 memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4853 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4854 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4855 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4856 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4857 // we are going to truncate pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4858 pszDestEnd--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4859 cchRemaining++;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4860
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4861 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4862 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4863
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4864 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4865 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4866 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4867 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4868
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4869 if (FAILED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4870 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4871 if (pszDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4872 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4873 if (dwFlags & STRSAFE_FILL_ON_FAILURE)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4874 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4875 memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4876
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4877 if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4878 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4879 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4880 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4881 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4882 else if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4883 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4884 pszDestEnd = pszDest + cchDest - 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4885 cchRemaining = 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4886
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4887 // null terminate the end of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4888 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4889 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4890 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4891
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4892 if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4893 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4894 if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4895 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4896 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4897 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4898
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4899 // null terminate the beginning of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4900 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4901 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4902 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4903 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4904 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4905
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4906 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4907 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4908 if (ppszDestEnd)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4909 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4910 *ppszDestEnd = pszDestEnd;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4911 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4912
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4913 if (pcchRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4914 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4915 *pcchRemaining = cchRemaining;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4916 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4917 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4918
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4919 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4920 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4921
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4922 STRSAFEAPI StringCatWorkerA(char* pszDest, size_t cchDest, const char* pszSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4923 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4924 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4925 size_t cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4926
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4927 hr = StringLengthWorkerA(pszDest, cchDest, &cchDestCurrent);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4928
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4929 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4930 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4931 hr = StringCopyWorkerA(pszDest + cchDestCurrent,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4932 cchDest - cchDestCurrent,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4933 pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4934 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4935
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4936 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4937 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4938
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4939 STRSAFEAPI StringCatWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4940 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4941 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4942 size_t cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4943
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4944 hr = StringLengthWorkerW(pszDest, cchDest, &cchDestCurrent);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4945
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4946 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4947 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4948 hr = StringCopyWorkerW(pszDest + cchDestCurrent,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4949 cchDest - cchDestCurrent,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4950 pszSrc);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4951 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4952
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4953 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4954 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4955
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4956 STRSAFEAPI StringCatExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4957 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4958 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4959 char* pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4960 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4961
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4962 // ASSERT(cbDest == (cchDest * sizeof(char)) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4963 // cbDest == (cchDest * sizeof(char)) + (cbDest % sizeof(char)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4964
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4965 // only accept valid flags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4966 if (dwFlags & (~STRSAFE_VALID_FLAGS))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4967 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4968 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4969 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4970 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4971 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4972 size_t cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4973
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4974 if (dwFlags & STRSAFE_IGNORE_NULLS)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4975 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4976 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4977 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4978 if ((cchDest == 0) && (cbDest == 0))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4979 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4980 cchDestCurrent = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4981 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4982 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4983 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4984 // NULL pszDest and non-zero cchDest/cbDest is invalid
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4985 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4986 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4987 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4988 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4989 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4990 hr = StringLengthWorkerA(pszDest, cchDest, &cchDestCurrent);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4991
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4992 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4993 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4994 pszDestEnd = pszDest + cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4995 cchRemaining = cchDest - cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4996 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4997 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4998
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
4999 if (pszSrc == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5000 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5001 pszSrc = "";
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5002 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5003 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5004 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5005 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5006 hr = StringLengthWorkerA(pszDest, cchDest, &cchDestCurrent);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5007
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5008 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5009 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5010 pszDestEnd = pszDest + cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5011 cchRemaining = cchDest - cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5012 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5013 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5014
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5015 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5016 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5017 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5018 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5019 // only fail if there was actually src data to append
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5020 if (*pszSrc != '\0')
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5021 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5022 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5023 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5024 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5025 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5026 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5027 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5028 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5029 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5030 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5031 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5032 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5033 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5034 // we handle the STRSAFE_FILL_ON_FAILURE and STRSAFE_NULL_ON_FAILURE cases below, so do not pass
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5035 // those flags through
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5036 hr = StringCopyExWorkerA(pszDestEnd,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5037 cchRemaining,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5038 (cchRemaining * sizeof(char)) + (cbDest % sizeof(char)),
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5039 pszSrc,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5040 &pszDestEnd,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5041 &cchRemaining,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5042 dwFlags & (~(STRSAFE_FILL_ON_FAILURE | STRSAFE_NULL_ON_FAILURE)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5043 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5044 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5045 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5046
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5047 if (FAILED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5048 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5049 if (pszDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5050 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5051 // STRSAFE_NO_TRUNCATION is taken care of by StringCopyExWorkerA()
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5052
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5053 if (dwFlags & STRSAFE_FILL_ON_FAILURE)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5054 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5055 memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5056
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5057 if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5058 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5059 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5060 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5061 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5062 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5063 if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5064 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5065 pszDestEnd = pszDest + cchDest - 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5066 cchRemaining = 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5067
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5068 // null terminate the end of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5069 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5070 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5071 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5072
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5073 if (dwFlags & STRSAFE_NULL_ON_FAILURE)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5074 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5075 if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5076 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5077 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5078 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5079
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5080 // null terminate the beginning of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5081 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5082 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5083 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5084 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5085 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5086
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5087 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5088 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5089 if (ppszDestEnd)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5090 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5091 *ppszDestEnd = pszDestEnd;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5092 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5093
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5094 if (pcchRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5095 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5096 *pcchRemaining = cchRemaining;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5097 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5098 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5099
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5100 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5101 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5102
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5103 STRSAFEAPI StringCatExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, const wchar_t* pszSrc, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5104 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5105 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5106 wchar_t* pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5107 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5108
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5109 // ASSERT(cbDest == (cchDest * sizeof(wchar_t)) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5110 // cbDest == (cchDest * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5111
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5112 // only accept valid flags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5113 if (dwFlags & (~STRSAFE_VALID_FLAGS))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5114 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5115 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5116 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5117 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5118 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5119 size_t cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5120
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5121 if (dwFlags & STRSAFE_IGNORE_NULLS)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5122 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5123 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5124 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5125 if ((cchDest == 0) && (cbDest == 0))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5126 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5127 cchDestCurrent = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5128 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5129 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5130 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5131 // NULL pszDest and non-zero cchDest/cbDest is invalid
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5132 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5133 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5134 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5135 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5136 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5137 hr = StringLengthWorkerW(pszDest, cchDest, &cchDestCurrent);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5138
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5139 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5140 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5141 pszDestEnd = pszDest + cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5142 cchRemaining = cchDest - cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5143 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5144 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5145
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5146 if (pszSrc == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5147 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5148 pszSrc = L"";
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5149 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5150 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5151 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5152 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5153 hr = StringLengthWorkerW(pszDest, cchDest, &cchDestCurrent);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5154
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5155 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5156 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5157 pszDestEnd = pszDest + cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5158 cchRemaining = cchDest - cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5159 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5160 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5161
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5162 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5163 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5164 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5165 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5166 // only fail if there was actually src data to append
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5167 if (*pszSrc != L'\0')
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5168 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5169 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5170 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5171 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5172 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5173 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5174 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5175 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5176 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5177 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5178 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5179 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5180 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5181 // we handle the STRSAFE_FILL_ON_FAILURE and STRSAFE_NULL_ON_FAILURE cases below, so do not pass
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5182 // those flags through
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5183 hr = StringCopyExWorkerW(pszDestEnd,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5184 cchRemaining,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5185 (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)),
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5186 pszSrc,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5187 &pszDestEnd,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5188 &cchRemaining,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5189 dwFlags & (~(STRSAFE_FILL_ON_FAILURE | STRSAFE_NULL_ON_FAILURE)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5190 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5191 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5192 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5193
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5194 if (FAILED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5195 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5196 if (pszDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5197 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5198 // STRSAFE_NO_TRUNCATION is taken care of by StringCopyExWorkerW()
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5199
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5200 if (dwFlags & STRSAFE_FILL_ON_FAILURE)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5201 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5202 memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5203
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5204 if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5205 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5206 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5207 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5208 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5209 else if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5210 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5211 pszDestEnd = pszDest + cchDest - 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5212 cchRemaining = 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5213
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5214 // null terminate the end of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5215 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5216 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5217 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5218
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5219 if (dwFlags & STRSAFE_NULL_ON_FAILURE)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5220 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5221 if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5222 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5223 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5224 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5225
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5226 // null terminate the beginning of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5227 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5228 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5229 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5230 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5231 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5232
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5233 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5234 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5235 if (ppszDestEnd)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5236 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5237 *ppszDestEnd = pszDestEnd;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5238 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5239
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5240 if (pcchRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5241 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5242 *pcchRemaining = cchRemaining;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5243 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5244 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5245
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5246 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5247 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5248
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5249 STRSAFEAPI StringCatNWorkerA(char* pszDest, size_t cchDest, const char* pszSrc, size_t cchMaxAppend)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5250 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5251 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5252 size_t cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5253
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5254 hr = StringLengthWorkerA(pszDest, cchDest, &cchDestCurrent);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5255
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5256 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5257 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5258 hr = StringCopyNWorkerA(pszDest + cchDestCurrent,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5259 cchDest - cchDestCurrent,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5260 pszSrc,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5261 cchMaxAppend);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5262 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5263
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5264 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5265 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5266
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5267 STRSAFEAPI StringCatNWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszSrc, size_t cchMaxAppend)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5268 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5269 HRESULT hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5270 size_t cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5271
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5272 hr = StringLengthWorkerW(pszDest, cchDest, &cchDestCurrent);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5273
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5274 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5275 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5276 hr = StringCopyNWorkerW(pszDest + cchDestCurrent,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5277 cchDest - cchDestCurrent,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5278 pszSrc,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5279 cchMaxAppend);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5280 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5281
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5282 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5283 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5284
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5285 STRSAFEAPI StringCatNExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, size_t cchMaxAppend, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5286 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5287 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5288 char* pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5289 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5290 size_t cchDestCurrent = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5291
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5292 // ASSERT(cbDest == (cchDest * sizeof(char)) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5293 // cbDest == (cchDest * sizeof(char)) + (cbDest % sizeof(char)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5294
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5295 // only accept valid flags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5296 if (dwFlags & (~STRSAFE_VALID_FLAGS))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5297 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5298 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5299 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5300 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5301 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5302 if (dwFlags & STRSAFE_IGNORE_NULLS)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5303 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5304 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5305 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5306 if ((cchDest == 0) && (cbDest == 0))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5307 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5308 cchDestCurrent = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5309 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5310 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5311 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5312 // NULL pszDest and non-zero cchDest/cbDest is invalid
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5313 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5314 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5315 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5316 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5317 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5318 hr = StringLengthWorkerA(pszDest, cchDest, &cchDestCurrent);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5319
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5320 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5321 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5322 pszDestEnd = pszDest + cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5323 cchRemaining = cchDest - cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5324 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5325 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5326
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5327 if (pszSrc == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5328 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5329 pszSrc = "";
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5330 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5331 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5332 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5333 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5334 hr = StringLengthWorkerA(pszDest, cchDest, &cchDestCurrent);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5335
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5336 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5337 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5338 pszDestEnd = pszDest + cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5339 cchRemaining = cchDest - cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5340 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5341 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5342
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5343 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5344 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5345 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5346 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5347 // only fail if there was actually src data to append
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5348 if (*pszSrc != '\0')
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5349 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5350 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5351 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5352 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5353 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5354 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5355 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5356 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5357 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5358 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5359 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5360 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5361 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5362 // we handle the STRSAFE_FILL_ON_FAILURE and STRSAFE_NULL_ON_FAILURE cases below, so do not pass
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5363 // those flags through
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5364 hr = StringCopyNExWorkerA(pszDestEnd,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5365 cchRemaining,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5366 (cchRemaining * sizeof(char)) + (cbDest % sizeof(char)),
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5367 pszSrc,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5368 cchMaxAppend,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5369 &pszDestEnd,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5370 &cchRemaining,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5371 dwFlags & (~(STRSAFE_FILL_ON_FAILURE | STRSAFE_NULL_ON_FAILURE)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5372 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5373 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5374 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5375
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5376 if (FAILED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5377 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5378 if (pszDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5379 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5380 // STRSAFE_NO_TRUNCATION is taken care of by StringCopyNExWorkerA()
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5381
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5382 if (dwFlags & STRSAFE_FILL_ON_FAILURE)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5383 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5384 memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5385
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5386 if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5387 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5388 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5389 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5390 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5391 else if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5392 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5393 pszDestEnd = pszDest + cchDest - 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5394 cchRemaining = 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5395
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5396 // null terminate the end of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5397 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5398 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5399 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5400
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5401 if (dwFlags & (STRSAFE_NULL_ON_FAILURE))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5402 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5403 if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5404 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5405 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5406 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5407
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5408 // null terminate the beginning of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5409 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5410 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5411 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5412 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5413 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5414
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5415 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5416 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5417 if (ppszDestEnd)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5418 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5419 *ppszDestEnd = pszDestEnd;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5420 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5421
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5422 if (pcchRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5423 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5424 *pcchRemaining = cchRemaining;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5425 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5426 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5427
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5428 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5429 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5430
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5431 STRSAFEAPI StringCatNExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, const wchar_t* pszSrc, size_t cchMaxAppend, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5432 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5433 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5434 wchar_t* pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5435 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5436 size_t cchDestCurrent = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5437
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5438
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5439 // ASSERT(cbDest == (cchDest * sizeof(wchar_t)) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5440 // cbDest == (cchDest * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5441
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5442 // only accept valid flags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5443 if (dwFlags & (~STRSAFE_VALID_FLAGS))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5444 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5445 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5446 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5447 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5448 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5449 if (dwFlags & STRSAFE_IGNORE_NULLS)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5450 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5451 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5452 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5453 if ((cchDest == 0) && (cbDest == 0))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5454 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5455 cchDestCurrent = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5456 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5457 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5458 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5459 // NULL pszDest and non-zero cchDest/cbDest is invalid
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5460 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5461 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5462 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5463 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5464 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5465 hr = StringLengthWorkerW(pszDest, cchDest, &cchDestCurrent);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5466
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5467 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5468 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5469 pszDestEnd = pszDest + cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5470 cchRemaining = cchDest - cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5471 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5472 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5473
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5474 if (pszSrc == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5475 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5476 pszSrc = L"";
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5477 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5478 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5479 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5480 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5481 hr = StringLengthWorkerW(pszDest, cchDest, &cchDestCurrent);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5482
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5483 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5484 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5485 pszDestEnd = pszDest + cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5486 cchRemaining = cchDest - cchDestCurrent;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5487 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5488 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5489
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5490 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5491 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5492 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5493 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5494 // only fail if there was actually src data to append
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5495 if (*pszSrc != L'\0')
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5496 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5497 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5498 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5499 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5500 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5501 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5502 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5503 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5504 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5505 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5506 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5507 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5508 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5509 // we handle the STRSAFE_FILL_ON_FAILURE and STRSAFE_NULL_ON_FAILURE cases below, so do not pass
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5510 // those flags through
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5511 hr = StringCopyNExWorkerW(pszDestEnd,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5512 cchRemaining,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5513 (cchRemaining * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)),
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5514 pszSrc,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5515 cchMaxAppend,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5516 &pszDestEnd,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5517 &cchRemaining,
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5518 dwFlags & (~(STRSAFE_FILL_ON_FAILURE | STRSAFE_NULL_ON_FAILURE)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5519 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5520 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5521 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5522
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5523 if (FAILED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5524 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5525 if (pszDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5526 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5527 // STRSAFE_NO_TRUNCATION is taken care of by StringCopyNExWorkerW()
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5528
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5529 if (dwFlags & STRSAFE_FILL_ON_FAILURE)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5530 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5531 memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5532
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5533 if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5534 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5535 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5536 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5537 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5538 else if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5539 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5540 pszDestEnd = pszDest + cchDest - 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5541 cchRemaining = 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5542
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5543 // null terminate the end of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5544 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5545 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5546 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5547
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5548 if (dwFlags & (STRSAFE_NULL_ON_FAILURE))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5549 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5550 if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5551 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5552 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5553 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5554
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5555 // null terminate the beginning of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5556 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5557 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5558 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5559 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5560 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5561
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5562 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5563 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5564 if (ppszDestEnd)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5565 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5566 *ppszDestEnd = pszDestEnd;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5567 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5568
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5569 if (pcchRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5570 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5571 *pcchRemaining = cchRemaining;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5572 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5573 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5574
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5575 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5576 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5577
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5578 STRSAFEAPI StringVPrintfWorkerA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5579 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5580 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5581
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5582 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5583 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5584 // can not null terminate a zero-byte dest buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5585 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5586 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5587 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5588 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5589 int iRet;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5590 size_t cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5591
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5592 // leave the last space for the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5593 cchMax = cchDest - 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5594
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5595 iRet = _vsnprintf(pszDest, cchMax, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5596 // ASSERT((iRet < 0) || (((size_t)iRet) <= cchMax));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5597
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5598 if ((iRet < 0) || (((size_t)iRet) > cchMax))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5599 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5600 // need to null terminate the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5601 pszDest += cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5602 *pszDest = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5603
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5604 // we have truncated pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5605 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5606 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5607 else if (((size_t)iRet) == cchMax)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5608 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5609 // need to null terminate the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5610 pszDest += cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5611 *pszDest = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5612 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5613 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5614
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5615 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5616 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5617
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5618 STRSAFEAPI StringVPrintfWorkerW(wchar_t* pszDest, size_t cchDest, const wchar_t* pszFormat, va_list argList)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5619 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5620 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5621
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5622 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5623 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5624 // can not null terminate a zero-byte dest buffer
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5625 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5626 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5627 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5628 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5629 int iRet;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5630 size_t cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5631
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5632 // leave the last space for the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5633 cchMax = cchDest - 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5634
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5635 iRet = _vsnwprintf(pszDest, cchMax, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5636 // ASSERT((iRet < 0) || (((size_t)iRet) <= cchMax));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5637
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5638 if ((iRet < 0) || (((size_t)iRet) > cchMax))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5639 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5640 // need to null terminate the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5641 pszDest += cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5642 *pszDest = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5643
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5644 // we have truncated pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5645 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5646 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5647 else if (((size_t)iRet) == cchMax)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5648 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5649 // need to null terminate the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5650 pszDest += cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5651 *pszDest = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5652 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5653 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5654
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5655 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5656 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5657
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5658 STRSAFEAPI StringVPrintfExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5659 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5660 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5661 char* pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5662 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5663
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5664 // ASSERT(cbDest == (cchDest * sizeof(char)) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5665 // cbDest == (cchDest * sizeof(char)) + (cbDest % sizeof(char)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5666
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5667 // only accept valid flags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5668 if (dwFlags & (~STRSAFE_VALID_FLAGS))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5669 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5670 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5671 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5672 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5673 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5674 if (dwFlags & STRSAFE_IGNORE_NULLS)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5675 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5676 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5677 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5678 if ((cchDest != 0) || (cbDest != 0))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5679 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5680 // NULL pszDest and non-zero cchDest/cbDest is invalid
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5681 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5682 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5683 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5684
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5685 if (pszFormat == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5686 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5687 pszFormat = "";
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5688 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5689 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5690
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5691 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5692 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5693 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5694 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5695 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5696 cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5697
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5698 // only fail if there was actually a non-empty format string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5699 if (*pszFormat != '\0')
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5700 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5701 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5702 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5703 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5704 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5705 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5706 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5707 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5708 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5709 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5710 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5711 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5712 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5713 int iRet;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5714 size_t cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5715
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5716 // leave the last space for the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5717 cchMax = cchDest - 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5718
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5719 iRet = _vsnprintf(pszDest, cchMax, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5720 // ASSERT((iRet < 0) || (((size_t)iRet) <= cchMax));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5721
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5722 if ((iRet < 0) || (((size_t)iRet) > cchMax))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5723 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5724 // we have truncated pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5725 pszDestEnd = pszDest + cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5726 cchRemaining = 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5727
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5728 // need to null terminate the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5729 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5730
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5731 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5732 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5733 else if (((size_t)iRet) == cchMax)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5734 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5735 // string fit perfectly
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5736 pszDestEnd = pszDest + cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5737 cchRemaining = 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5738
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5739 // need to null terminate the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5740 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5741 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5742 else if (((size_t)iRet) < cchMax)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5743 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5744 // there is extra room
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5745 pszDestEnd = pszDest + iRet;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5746 cchRemaining = cchDest - iRet;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5747
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5748 if (dwFlags & STRSAFE_FILL_BEHIND_NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5749 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5750 memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(char)) + (cbDest % sizeof(char)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5751 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5752 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5753 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5754 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5755 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5756
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5757 if (FAILED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5758 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5759 if (pszDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5760 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5761 if (dwFlags & STRSAFE_FILL_ON_FAILURE)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5762 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5763 memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5764
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5765 if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5766 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5767 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5768 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5769 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5770 else if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5771 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5772 pszDestEnd = pszDest + cchDest - 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5773 cchRemaining = 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5774
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5775 // null terminate the end of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5776 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5777 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5778 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5779
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5780 if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5781 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5782 if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5783 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5784 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5785 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5786
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5787 // null terminate the beginning of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5788 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5789 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5790 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5791 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5792 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5793
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5794 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5795 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5796 if (ppszDestEnd)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5797 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5798 *ppszDestEnd = pszDestEnd;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5799 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5800
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5801 if (pcchRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5802 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5803 *pcchRemaining = cchRemaining;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5804 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5805 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5806
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5807 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5808 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5809
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5810 STRSAFEAPI StringVPrintfExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const wchar_t* pszFormat, va_list argList)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5811 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5812 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5813 wchar_t* pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5814 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5815
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5816 // ASSERT(cbDest == (cchDest * sizeof(wchar_t)) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5817 // cbDest == (cchDest * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5818
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5819 // only accept valid flags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5820 if (dwFlags & (~STRSAFE_VALID_FLAGS))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5821 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5822 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5823 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5824 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5825 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5826 if (dwFlags & STRSAFE_IGNORE_NULLS)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5827 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5828 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5829 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5830 if ((cchDest != 0) || (cbDest != 0))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5831 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5832 // NULL pszDest and non-zero cchDest/cbDest is invalid
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5833 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5834 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5835 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5836
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5837 if (pszFormat == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5838 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5839 pszFormat = L"";
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5840 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5841 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5842
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5843 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5844 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5845 if (cchDest == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5846 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5847 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5848 cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5849
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5850 // only fail if there was actually a non-empty format string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5851 if (*pszFormat != L'\0')
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5852 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5853 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5854 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5855 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5856 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5857 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5858 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5859 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5860 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5861 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5862 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5863 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5864 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5865 int iRet;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5866 size_t cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5867
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5868 // leave the last space for the null terminator
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5869 cchMax = cchDest - 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5870
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5871 iRet = _vsnwprintf(pszDest, cchMax, pszFormat, argList);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5872 // ASSERT((iRet < 0) || (((size_t)iRet) <= cchMax));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5873
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5874 if ((iRet < 0) || (((size_t)iRet) > cchMax))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5875 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5876 // we have truncated pszDest
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5877 pszDestEnd = pszDest + cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5878 cchRemaining = 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5879
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5880 // need to null terminate the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5881 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5882
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5883 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5884 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5885 else if (((size_t)iRet) == cchMax)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5886 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5887 // string fit perfectly
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5888 pszDestEnd = pszDest + cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5889 cchRemaining = 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5890
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5891 // need to null terminate the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5892 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5893 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5894 else if (((size_t)iRet) < cchMax)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5895 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5896 // there is extra room
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5897 pszDestEnd = pszDest + iRet;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5898 cchRemaining = cchDest - iRet;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5899
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5900 if (dwFlags & STRSAFE_FILL_BEHIND_NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5901 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5902 memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5903 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5904 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5905 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5906 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5907 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5908
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5909 if (FAILED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5910 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5911 if (pszDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5912 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5913 if (dwFlags & STRSAFE_FILL_ON_FAILURE)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5914 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5915 memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5916
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5917 if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5918 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5919 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5920 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5921 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5922 else if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5923 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5924 pszDestEnd = pszDest + cchDest - 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5925 cchRemaining = 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5926
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5927 // null terminate the end of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5928 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5929 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5930 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5931
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5932 if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5933 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5934 if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5935 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5936 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5937 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5938
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5939 // null terminate the beginning of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5940 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5941 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5942 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5943 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5944 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5945
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5946 if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5947 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5948 if (ppszDestEnd)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5949 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5950 *ppszDestEnd = pszDestEnd;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5951 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5952
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5953 if (pcchRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5954 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5955 *pcchRemaining = cchRemaining;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5956 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5957 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5958
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5959 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5960 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5961
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5962 STRSAFEAPI StringLengthWorkerA(const char* psz, size_t cchMax, size_t* pcch)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5963 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5964 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5965 size_t cchMaxPrev = cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5966
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5967 while (cchMax && (*psz != '\0'))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5968 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5969 psz++;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5970 cchMax--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5971 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5972
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5973 if (cchMax == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5974 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5975 // the string is longer than cchMax
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5976 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5977 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5978
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5979 if (SUCCEEDED(hr) && pcch)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5980 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5981 *pcch = cchMaxPrev - cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5982 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5983
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5984 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5985 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5986
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5987 STRSAFEAPI StringLengthWorkerW(const wchar_t* psz, size_t cchMax, size_t* pcch)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5988 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5989 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5990 size_t cchMaxPrev = cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5991
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5992 while (cchMax && (*psz != L'\0'))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5993 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5994 psz++;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5995 cchMax--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5996 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5997
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5998 if (cchMax == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
5999 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6000 // the string is longer than cchMax
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6001 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6002 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6003
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6004 if (SUCCEEDED(hr) && pcch)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6005 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6006 *pcch = cchMaxPrev - cchMax;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6007 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6008
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6009 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6010 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6011 #endif // STRSAFE_INLINE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6012
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6013 #ifndef STRSAFE_LIB_IMPL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6014 STRSAFE_INLINE_API StringGetsExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6015 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6016 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6017 char* pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6018 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6019
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6020 // ASSERT(cbDest == (cchDest * sizeof(char)) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6021 // cbDest == (cchDest * sizeof(char)) + (cbDest % sizeof(char)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6022
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6023 // only accept valid flags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6024 if (dwFlags & (~STRSAFE_VALID_FLAGS))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6025 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6026 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6027 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6028 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6029 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6030 if (dwFlags & STRSAFE_IGNORE_NULLS)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6031 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6032 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6033 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6034 if ((cchDest != 0) || (cbDest != 0))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6035 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6036 // NULL pszDest and non-zero cchDest/cbDest is invalid
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6037 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6038 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6039 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6040 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6041
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6042 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6043 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6044 if (cchDest <= 1)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6045 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6046 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6047 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6048
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6049 if (cchDest == 1)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6050 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6051 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6052 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6053
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6054 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6055 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6056 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6057 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6058 char ch;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6059
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6060 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6061 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6062
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6063 while ((cchRemaining > 1) && (ch = (char)getc(stdin)) != '\n')
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6064 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6065 if (ch == EOF)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6066 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6067 if (pszDestEnd == pszDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6068 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6069 // we failed to read anything from stdin
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6070 hr = STRSAFE_E_END_OF_FILE;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6071 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6072 break;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6073 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6074
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6075 *pszDestEnd = ch;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6076
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6077 pszDestEnd++;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6078 cchRemaining--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6079 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6080
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6081 if (cchRemaining > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6082 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6083 // there is extra room
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6084 if (dwFlags & STRSAFE_FILL_BEHIND_NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6085 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6086 memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(char)) + (cbDest % sizeof(char)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6087 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6088 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6089
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6090 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6091 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6092 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6093 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6094
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6095 if (FAILED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6096 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6097 if (pszDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6098 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6099 if (dwFlags & STRSAFE_FILL_ON_FAILURE)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6100 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6101 memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6102
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6103 if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6104 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6105 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6106 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6107 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6108 else if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6109 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6110 pszDestEnd = pszDest + cchDest - 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6111 cchRemaining = 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6112
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6113 // null terminate the end of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6114 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6115 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6116 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6117
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6118 if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6119 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6120 if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6121 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6122 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6123 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6124
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6125 // null terminate the beginning of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6126 *pszDestEnd = '\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6127 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6128 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6129 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6130 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6131
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6132 if (SUCCEEDED(hr) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6133 (hr == STRSAFE_E_INSUFFICIENT_BUFFER) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6134 (hr == STRSAFE_E_END_OF_FILE))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6135 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6136 if (ppszDestEnd)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6137 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6138 *ppszDestEnd = pszDestEnd;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6139 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6140
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6141 if (pcchRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6142 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6143 *pcchRemaining = cchRemaining;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6144 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6145 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6146
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6147 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6148 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6149
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6150 STRSAFE_INLINE_API StringGetsExWorkerW(wchar_t* pszDest, size_t cchDest, size_t cbDest, wchar_t** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6151 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6152 HRESULT hr = S_OK;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6153 wchar_t* pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6154 size_t cchRemaining = 0;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6155
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6156 // ASSERT(cbDest == (cchDest * sizeof(char)) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6157 // cbDest == (cchDest * sizeof(char)) + (cbDest % sizeof(char)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6158
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6159 // only accept valid flags
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6160 if (dwFlags & (~STRSAFE_VALID_FLAGS))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6161 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6162 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6163 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6164 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6165 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6166 if (dwFlags & STRSAFE_IGNORE_NULLS)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6167 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6168 if (pszDest == NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6169 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6170 if ((cchDest != 0) || (cbDest != 0))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6171 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6172 // NULL pszDest and non-zero cchDest/cbDest is invalid
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6173 hr = STRSAFE_E_INVALID_PARAMETER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6174 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6175 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6176 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6177
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6178 if (SUCCEEDED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6179 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6180 if (cchDest <= 1)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6181 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6182 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6183 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6184
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6185 if (cchDest == 1)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6186 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6187 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6188 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6189
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6190 hr = STRSAFE_E_INSUFFICIENT_BUFFER;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6191 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6192 else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6193 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6194 wchar_t ch;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6195
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6196 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6197 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6198
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6199 while ((cchRemaining > 1) && (ch = (wchar_t)getwc(stdin)) != L'\n')
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6200 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6201 if (ch == EOF)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6202 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6203 if (pszDestEnd == pszDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6204 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6205 // we failed to read anything from stdin
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6206 hr = STRSAFE_E_END_OF_FILE;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6207 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6208 break;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6209 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6210
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6211 *pszDestEnd = ch;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6212
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6213 pszDestEnd++;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6214 cchRemaining--;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6215 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6216
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6217 if (cchRemaining > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6218 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6219 // there is extra room
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6220 if (dwFlags & STRSAFE_FILL_BEHIND_NULL)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6221 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6222 memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(wchar_t)) + (cbDest % sizeof(wchar_t)));
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6223 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6224 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6225
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6226 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6227 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6228 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6229 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6230
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6231 if (FAILED(hr))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6232 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6233 if (pszDest)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6234 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6235 if (dwFlags & STRSAFE_FILL_ON_FAILURE)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6236 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6237 memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest);
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6238
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6239 if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6240 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6241 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6242 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6243 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6244 else if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6245 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6246 pszDestEnd = pszDest + cchDest - 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6247 cchRemaining = 1;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6248
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6249 // null terminate the end of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6250 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6251 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6252 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6253
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6254 if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6255 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6256 if (cchDest > 0)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6257 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6258 pszDestEnd = pszDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6259 cchRemaining = cchDest;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6260
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6261 // null terminate the beginning of the string
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6262 *pszDestEnd = L'\0';
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6263 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6264 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6265 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6266 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6267
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6268 if (SUCCEEDED(hr) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6269 (hr == STRSAFE_E_INSUFFICIENT_BUFFER) ||
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6270 (hr == STRSAFE_E_END_OF_FILE))
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6271 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6272 if (ppszDestEnd)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6273 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6274 *ppszDestEnd = pszDestEnd;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6275 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6276
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6277 if (pcchRemaining)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6278 {
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6279 *pcchRemaining = cchRemaining;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6280 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6281 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6282
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6283 return hr;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6284 }
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6285 #endif // !STRSAFE_LIB_IMPL
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6286
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6287
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6288 // Do not call these functions, they are worker functions for internal use within this file
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6289 #ifdef DEPRECATE_SUPPORTED
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6290 #pragma deprecated(StringCopyWorkerA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6291 #pragma deprecated(StringCopyWorkerW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6292 #pragma deprecated(StringCopyExWorkerA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6293 #pragma deprecated(StringCopyExWorkerW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6294 #pragma deprecated(StringCatWorkerA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6295 #pragma deprecated(StringCatWorkerW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6296 #pragma deprecated(StringCatExWorkerA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6297 #pragma deprecated(StringCatExWorkerW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6298 #pragma deprecated(StringCatNWorkerA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6299 #pragma deprecated(StringCatNWorkerW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6300 #pragma deprecated(StringCatNExWorkerA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6301 #pragma deprecated(StringCatNExWorkerW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6302 #pragma deprecated(StringVPrintfWorkerA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6303 #pragma deprecated(StringVPrintfWorkerW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6304 #pragma deprecated(StringVPrintfExWorkerA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6305 #pragma deprecated(StringVPrintfExWorkerW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6306 #pragma deprecated(StringLengthWorkerA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6307 #pragma deprecated(StringLengthWorkerW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6308 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6309 #define StringCopyWorkerA StringCopyWorkerA_instead_use_StringCchCopyA_or_StringCchCopyExA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6310 #define StringCopyWorkerW StringCopyWorkerW_instead_use_StringCchCopyW_or_StringCchCopyExW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6311 #define StringCopyExWorkerA StringCopyExWorkerA_instead_use_StringCchCopyA_or_StringCchCopyExA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6312 #define StringCopyExWorkerW StringCopyExWorkerW_instead_use_StringCchCopyW_or_StringCchCopyExW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6313 #define StringCatWorkerA StringCatWorkerA_instead_use_StringCchCatA_or_StringCchCatExA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6314 #define StringCatWorkerW StringCatWorkerW_instead_use_StringCchCatW_or_StringCchCatExW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6315 #define StringCatExWorkerA StringCatExWorkerA_instead_use_StringCchCatA_or_StringCchCatExA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6316 #define StringCatExWorkerW StringCatExWorkerW_instead_use_StringCchCatW_or_StringCchCatExW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6317 #define StringCatNWorkerA StringCatNWorkerA_instead_use_StringCchCatNA_or_StrincCbCatNA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6318 #define StringCatNWorkerW StringCatNWorkerW_instead_use_StringCchCatNW_or_StringCbCatNW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6319 #define StringCatNExWorkerA StringCatNExWorkerA_instead_use_StringCchCatNExA_or_StringCbCatNExA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6320 #define StringCatNExWorkerW StringCatNExWorkerW_instead_use_StringCchCatNExW_or_StringCbCatNExW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6321 #define StringVPrintfWorkerA StringVPrintfWorkerA_instead_use_StringCchVPrintfA_or_StringCchVPrintfExA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6322 #define StringVPrintfWorkerW StringVPrintfWorkerW_instead_use_StringCchVPrintfW_or_StringCchVPrintfExW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6323 #define StringVPrintfExWorkerA StringVPrintfExWorkerA_instead_use_StringCchVPrintfA_or_StringCchVPrintfExA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6324 #define StringVPrintfExWorkerW StringVPrintfExWorkerW_instead_use_StringCchVPrintfW_or_StringCchVPrintfExW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6325 #define StringLengthWorkerA StringLengthWorkerA_instead_use_StringCchLengthA_or_StringCbLengthA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6326 #define StringLengthWorkerW StringLengthWorkerW_instead_use_StringCchLengthW_or_StringCbLengthW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6327 #endif // !DEPRECATE_SUPPORTED
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6328
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6329
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6330 #ifndef STRSAFE_NO_DEPRECATE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6331 // Deprecate all of the unsafe functions to generate compiletime errors. If you do not want
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6332 // this then you can #define STRSAFE_NO_DEPRECATE before including this file.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6333 #ifdef DEPRECATE_SUPPORTED
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6334
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6335 // First all the names that are a/w variants (or shouldn't be #defined by now anyway).
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6336 #pragma deprecated(lstrcpyA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6337 #pragma deprecated(lstrcpyW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6338 #pragma deprecated(lstrcatA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6339 #pragma deprecated(lstrcatW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6340 #pragma deprecated(wsprintfA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6341 #pragma deprecated(wsprintfW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6342
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6343 #pragma deprecated(StrCpyW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6344 #pragma deprecated(StrCatW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6345 #pragma deprecated(StrNCatA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6346 #pragma deprecated(StrNCatW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6347 #pragma deprecated(StrCatNA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6348 #pragma deprecated(StrCatNW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6349 #pragma deprecated(wvsprintfA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6350 #pragma deprecated(wvsprintfW)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6351
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6352 #pragma deprecated(strcpy)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6353 #pragma deprecated(wcscpy)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6354 #pragma deprecated(strcat)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6355 #pragma deprecated(wcscat)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6356 #pragma deprecated(sprintf)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6357 #pragma deprecated(swprintf)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6358 #pragma deprecated(vsprintf)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6359 #pragma deprecated(vswprintf)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6360 #pragma deprecated(_snprintf)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6361 #pragma deprecated(_snwprintf)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6362 #pragma deprecated(_vsnprintf)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6363 #pragma deprecated(_vsnwprintf)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6364 #pragma deprecated(gets)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6365 #pragma deprecated(_getws)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6366
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6367 // Then all the windows.h names - we need to undef and redef based on UNICODE setting
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6368 #undef lstrcpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6369 #undef lstrcat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6370 #undef wsprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6371 #undef wvsprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6372 #pragma deprecated(lstrcpy)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6373 #pragma deprecated(lstrcat)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6374 #pragma deprecated(wsprintf)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6375 #pragma deprecated(wvsprintf)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6376 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6377 #define lstrcpy lstrcpyW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6378 #define lstrcat lstrcatW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6379 #define wsprintf wsprintfW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6380 #define wvsprintf wvsprintfW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6381 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6382 #define lstrcpy lstrcpyA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6383 #define lstrcat lstrcatA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6384 #define wsprintf wsprintfA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6385 #define wvsprintf wvsprintfA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6386 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6387
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6388 // Then the shlwapi names - they key off UNICODE also.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6389 #undef StrCpyA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6390 #undef StrCpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6391 #undef StrCatA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6392 #undef StrCat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6393 #undef StrNCat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6394 #undef StrCatN
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6395 #pragma deprecated(StrCpyA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6396 #pragma deprecated(StrCatA)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6397 #pragma deprecated(StrCatN)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6398 #pragma deprecated(StrCpy)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6399 #pragma deprecated(StrCat)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6400 #pragma deprecated(StrNCat)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6401 #define StrCpyA lstrcpyA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6402 #define StrCatA lstrcatA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6403 #define StrCatN StrNCat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6404 #ifdef UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6405 #define StrCpy StrCpyW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6406 #define StrCat StrCatW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6407 #define StrNCat StrNCatW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6408 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6409 #define StrCpy lstrcpyA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6410 #define StrCat lstrcatA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6411 #define StrNCat StrNCatA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6412 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6413
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6414 // Then all the CRT names - we need to undef/redef based on _UNICODE value.
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6415 #undef _tcscpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6416 #undef _ftcscpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6417 #undef _tcscat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6418 #undef _ftcscat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6419 #undef _stprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6420 #undef _sntprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6421 #undef _vstprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6422 #undef _vsntprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6423 #undef _getts
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6424 #pragma deprecated(_tcscpy)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6425 #pragma deprecated(_ftcscpy)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6426 #pragma deprecated(_tcscat)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6427 #pragma deprecated(_ftcscat)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6428 #pragma deprecated(_stprintf)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6429 #pragma deprecated(_sntprintf)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6430 #pragma deprecated(_vstprintf)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6431 #pragma deprecated(_vsntprintf)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6432 #pragma deprecated(_getts)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6433 #ifdef _UNICODE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6434 #define _tcscpy wcscpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6435 #define _ftcscpy wcscpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6436 #define _tcscat wcscat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6437 #define _ftcscat wcscat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6438 #define _stprintf swprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6439 #define _sntprintf _snwprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6440 #define _vstprintf vswprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6441 #define _vsntprintf _vsnwprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6442 #define _getts _getws
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6443 #else
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6444 #define _tcscpy strcpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6445 #define _ftcscpy strcpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6446 #define _tcscat strcat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6447 #define _ftcscat strcat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6448 #define _stprintf sprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6449 #define _sntprintf _snprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6450 #define _vstprintf vsprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6451 #define _vsntprintf _vsnprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6452 #define _getts gets
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6453 #endif
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6454
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6455 #else // DEPRECATE_SUPPORTED
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6456
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6457 #undef strcpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6458 #define strcpy strcpy_instead_use_StringCbCopyA_or_StringCchCopyA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6459
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6460 #undef wcscpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6461 #define wcscpy wcscpy_instead_use_StringCbCopyW_or_StringCchCopyW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6462
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6463 #undef strcat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6464 #define strcat strcat_instead_use_StringCbCatA_or_StringCchCatA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6465
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6466 #undef wcscat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6467 #define wcscat wcscat_instead_use_StringCbCatW_or_StringCchCatW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6468
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6469 #undef sprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6470 #define sprintf sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6471
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6472 #undef swprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6473 #define swprintf swprintf_instead_use_StringCbPrintfW_or_StringCchPrintfW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6474
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6475 #undef vsprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6476 #define vsprintf vsprintf_instead_use_StringCbVPrintfA_or_StringCchVPrintfA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6477
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6478 #undef vswprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6479 #define vswprintf vswprintf_instead_use_StringCbVPrintfW_or_StringCchVPrintfW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6480
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6481 #undef _snprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6482 #define _snprintf _snprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6483
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6484 #undef _snwprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6485 #define _snwprintf _snwprintf_instead_use_StringCbPrintfW_or_StringCchPrintfW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6486
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6487 #undef _vsnprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6488 #define _vsnprintf _vsnprintf_instead_use_StringCbVPrintfA_or_StringCchVPrintfA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6489
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6490 #undef _vsnwprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6491 #define _vsnwprintf _vsnwprintf_instead_use_StringCbVPrintfW_or_StringCchVPrintfW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6492
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6493 #undef strcpyA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6494 #define strcpyA strcpyA_instead_use_StringCbCopyA_or_StringCchCopyA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6495
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6496 #undef strcpyW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6497 #define strcpyW strcpyW_instead_use_StringCbCopyW_or_StringCchCopyW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6498
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6499 #undef lstrcpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6500 #define lstrcpy lstrcpy_instead_use_StringCbCopy_or_StringCchCopy;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6501
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6502 #undef lstrcpyA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6503 #define lstrcpyA lstrcpyA_instead_use_StringCbCopyA_or_StringCchCopyA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6504
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6505 #undef lstrcpyW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6506 #define lstrcpyW lstrcpyW_instead_use_StringCbCopyW_or_StringCchCopyW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6507
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6508 #undef StrCpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6509 #define StrCpy StrCpy_instead_use_StringCbCopy_or_StringCchCopy;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6510
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6511 #undef StrCpyA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6512 #define StrCpyA StrCpyA_instead_use_StringCbCopyA_or_StringCchCopyA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6513
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6514 #undef StrCpyW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6515 #define StrCpyW StrCpyW_instead_use_StringCbCopyW_or_StringCchCopyW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6516
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6517 #undef _tcscpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6518 #define _tcscpy _tcscpy_instead_use_StringCbCopy_or_StringCchCopy;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6519
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6520 #undef _ftcscpy
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6521 #define _ftcscpy _ftcscpy_instead_use_StringCbCopy_or_StringCchCopy;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6522
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6523 #undef lstrcat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6524 #define lstrcat lstrcat_instead_use_StringCbCat_or_StringCchCat;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6525
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6526 #undef lstrcatA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6527 #define lstrcatA lstrcatA_instead_use_StringCbCatA_or_StringCchCatA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6528
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6529 #undef lstrcatW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6530 #define lstrcatW lstrcatW_instead_use_StringCbCatW_or_StringCchCatW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6531
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6532 #undef StrCat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6533 #define StrCat StrCat_instead_use_StringCbCat_or_StringCchCat;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6534
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6535 #undef StrCatA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6536 #define StrCatA StrCatA_instead_use_StringCbCatA_or_StringCchCatA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6537
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6538 #undef StrCatW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6539 #define StrCatW StrCatW_instead_use_StringCbCatW_or_StringCchCatW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6540
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6541 #undef StrNCat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6542 #define StrNCat StrNCat_instead_use_StringCbCatN_or_StringCchCatN;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6543
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6544 #undef StrNCatA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6545 #define StrNCatA StrNCatA_instead_use_StringCbCatNA_or_StringCchCatNA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6546
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6547 #undef StrNCatW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6548 #define StrNCatW StrNCatW_instead_use_StringCbCatNW_or_StringCchCatNW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6549
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6550 #undef StrCatN
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6551 #define StrCatN StrCatN_instead_use_StringCbCatN_or_StringCchCatN;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6552
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6553 #undef StrCatNA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6554 #define StrCatNA StrCatNA_instead_use_StringCbCatNA_or_StringCchCatNA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6555
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6556 #undef StrCatNW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6557 #define StrCatNW StrCatNW_instead_use_StringCbCatNW_or_StringCchCatNW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6558
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6559 #undef _tcscat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6560 #define _tcscat _tcscat_instead_use_StringCbCat_or_StringCchCat;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6561
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6562 #undef _ftcscat
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6563 #define _ftcscat _ftcscat_instead_use_StringCbCat_or_StringCchCat;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6564
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6565 #undef wsprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6566 #define wsprintf wsprintf_instead_use_StringCbPrintf_or_StringCchPrintf;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6567
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6568 #undef wsprintfA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6569 #define wsprintfA wsprintfA_instead_use_StringCbPrintfA_or_StringCchPrintfA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6570
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6571 #undef wsprintfW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6572 #define wsprintfW wsprintfW_instead_use_StringCbPrintfW_or_StringCchPrintfW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6573
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6574 #undef wvsprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6575 #define wvsprintf wvsprintf_instead_use_StringCbVPrintf_or_StringCchVPrintf;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6576
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6577 #undef wvsprintfA
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6578 #define wvsprintfA wvsprintfA_instead_use_StringCbVPrintfA_or_StringCchVPrintfA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6579
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6580 #undef wvsprintfW
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6581 #define wvsprintfW wvsprintfW_instead_use_StringCbVPrintfW_or_StringCchVPrintfW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6582
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6583 #undef _vstprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6584 #define _vstprintf _vstprintf_instead_use_StringCbVPrintf_or_StringCchVPrintf;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6585
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6586 #undef _vsntprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6587 #define _vsntprintf _vsntprintf_instead_use_StringCbVPrintf_or_StringCchVPrintf;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6588
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6589 #undef _stprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6590 #define _stprintf _stprintf_instead_use_StringCbPrintf_or_StringCchPrintf;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6591
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6592 #undef _sntprintf
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6593 #define _sntprintf _sntprintf_instead_use_StringCbPrintf_or_StringCchPrintf;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6594
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6595 #undef _getts
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6596 #define _getts _getts_instead_use_StringCbGets_or_StringCchGets;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6597
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6598 #undef gets
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6599 #define gets _gets_instead_use_StringCbGetsA_or_StringCchGetsA;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6600
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6601 #undef _getws
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6602 #define _getws _getws_instead_use_StringCbGetsW_or_StringCchGetsW;
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6603
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6604 #endif // !DEPRECATE_SUPPORTED
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6605 #endif // !STRSAFE_NO_DEPRECATE
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6606
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6607 #ifdef _NTSTRSAFE_H_INCLUDED_
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6608 #pragma warning(pop)
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6609 #endif // _NTSTRSAFE_H_INCLUDED_
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6610
8b8875f5b359 Initial commit
Nomad
parents:
diff changeset
6611 #endif // _STRSAFE_H_INCLUDED_