diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2016-12-27 16:46:08 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2016-12-27 16:46:08 +0900 |
commit | db20f3f1bb8595633a7e16c8900fd401a453a6b5 (patch) | |
tree | e5435159cd1bf0519276363a6fe1663d1721bed3 /src/pal/inc/strsafe.h | |
parent | 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (diff) | |
download | coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.gz coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.bz2 coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.zip |
Imported Upstream version 1.0.0.9127upstream/1.0.0.9127
Diffstat (limited to 'src/pal/inc/strsafe.h')
-rw-r--r-- | src/pal/inc/strsafe.h | 1512 |
1 files changed, 1 insertions, 1511 deletions
diff --git a/src/pal/inc/strsafe.h b/src/pal/inc/strsafe.h index 5a9f0edd43..58749f27ee 100644 --- a/src/pal/inc/strsafe.h +++ b/src/pal/inc/strsafe.h @@ -32,7 +32,7 @@ #define _vsnprintf vsnprintf #endif // defined(PLATFORM_UNIX) && !defined (FEATURE_PAL) -#include <stdio.h> // for _vsnprintf, _vsnwprintf, getc, getwc +#include <stdio.h> // for _vsnprintf, getc, getwc #include <string.h> // for memset #include <stdarg.h> // for va_start, etc. @@ -146,10 +146,6 @@ STRSAFEAPI StringCatNWorkerA(char* pszDest, size_t cchDest, const char* pszSrc, STRSAFEAPI StringCatNWorkerW(WCHAR* pszDest, size_t cchDest, const WCHAR* pszSrc, size_t cchMaxAppend); STRSAFEAPI StringCatNExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, const char* pszSrc, size_t cchMaxAppend, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); STRSAFEAPI StringCatNExWorkerW(WCHAR* pszDest, size_t cchDest, size_t cbDest, const WCHAR* pszSrc, size_t cchMaxAppend, WCHAR** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags); -STRSAFEAPI StringVPrintfWorkerA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList); -STRSAFEAPI StringVPrintfWorkerW(WCHAR* pszDest, size_t cchDest, const WCHAR* pszFormat, va_list argList); -STRSAFEAPI StringVPrintfExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList); -STRSAFEAPI StringVPrintfExWorkerW(WCHAR* pszDest, size_t cchDest, size_t cbDest, WCHAR** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const WCHAR* pszFormat, va_list argList); STRSAFEAPI StringLengthWorkerA(const char* psz, size_t cchMax, size_t* pcch); STRSAFEAPI StringLengthWorkerW(const WCHAR* psz, size_t cchMax, size_t* pcch); #endif // STRSAFE_INLINE @@ -2356,1124 +2352,6 @@ STRSAFEAPI StringCbCatNExW(WCHAR* pszDest, size_t cbDest, const WCHAR* pszSrc, s #ifndef STRSAFE_NO_CCH_FUNCTIONS /*++ -STDAPI StringCchVPrintf(LPTSTR pszDest, - size_t cchDest, - LPCTSTR pszFormat, - va_list argList); - -Routine Description: - - This routine is a safer version of the C built-in function 'vsprintf'. - The size of the destination buffer (in characters) is a parameter and - this function will not write past the end of this buffer and it will - ALWAYS null terminate the destination buffer (unless it is zero length). - - This function returns a hresult, and not a pointer. It returns a S_OK - if the string was printed without truncation and null terminated, otherwise - it will return a failure code. In failure cases it will return a truncated - version of the ideal result. - -Arguments: - - pszDest - destination string - - cchDest - size of destination buffer in characters - length must be sufficient to hold the resulting formatted - string, including the null terminator. - - pszFormat - format string which must be null terminated - - argList - va_list from the variable arguments according to the - stdarg.h convention - -Notes: - Behavior is undefined if destination, format strings or any arguments - strings overlap. - - pszDest and pszFormat should not be NULL. See StringCchVPrintfEx if you - require the handling of NULL values. - -Return Value: - - S_OK - if there was sufficient space in the dest buffer for - the resultant string and it was null terminated. - - failure - you can use the macro HRESULT_CODE() to get a win32 error - code for all falure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the print operation - failed due to insufficient space. When this error occurs, - the destination buffer is modified to contain a truncated - version of the ideal result and is null terminated. This - is useful for situations where truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCchVPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList); -STRSAFEAPI StringCchVPrintfW(WCHAR* pszDest, size_t cchDest, const WCHAR* pszFormat, va_list argList); -#ifdef UNICODE -#define StringCchVPrintf StringCchVPrintfW -#else -#define StringCchVPrintf StringCchVPrintfA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchVPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList); - } - - return hr; -} - -#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX) -STRSAFEAPI StringCchVPrintfW(WCHAR* pszDest, size_t cchDest, const WCHAR* pszFormat, va_list argList) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringVPrintfWorkerW(pszDest, cchDest, pszFormat, argList); - } - - return hr; -} -#endif // FEATURE_PAL || !PLATFORM_UNIX -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI StringCbVPrintf(LPTSTR pszDest, - size_t cbDest, - LPCTSTR pszFormat, - va_list argList); - -Routine Description: - - This routine is a safer version of the C built-in function 'vsprintf'. - The size of the destination buffer (in bytes) is a parameter and - this function will not write past the end of this buffer and it will - ALWAYS null terminate the destination buffer (unless it is zero length). - - This function returns a hresult, and not a pointer. It returns a S_OK - if the string was printed without truncation and null terminated, otherwise - it will return a failure code. In failure cases it will return a truncated - version of the ideal result. - -Arguments: - - pszDest - destination string - - cbDest - size of destination buffer in bytes - length must be sufficient to hold the resulting formatted - string, including the null terminator. - - pszFormat - format string which must be null terminated - - argList - va_list from the variable arguments according to the - stdarg.h convention - -Notes: - Behavior is undefined if destination, format strings or any arguments - strings overlap. - - pszDest and pszFormat should not be NULL. See StringCbVPrintfEx if you - require the handling of NULL values. - - -Return Value: - - S_OK - if there was sufficient space in the dest buffer for - the resultant string and it was null terminated. - - failure - you can use the macro HRESULT_CODE() to get a win32 error - code for all falure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the print operation - failed due to insufficient space. When this error occurs, - the destination buffer is modified to contain a truncated - version of the ideal result and is null terminated. This - is useful for situations where truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCbVPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, va_list argList); -STRSAFEAPI StringCbVPrintfW(WCHAR* pszDest, size_t cbDest, const WCHAR* pszFormat, va_list argList); -#ifdef UNICODE -#define StringCbVPrintf StringCbVPrintfW -#else -#define StringCbVPrintf StringCbVPrintfA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbVPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, va_list argList) -{ - HRESULT hr; - size_t cchDest; - - cchDest = cbDest / sizeof(char); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList); - } - - return hr; -} - -#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX) -STRSAFEAPI StringCbVPrintfW(WCHAR* pszDest, size_t cbDest, const WCHAR* pszFormat, va_list argList) -{ - HRESULT hr; - size_t cchDest; - - cchDest = cbDest / sizeof(WCHAR); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringVPrintfWorkerW(pszDest, cchDest, pszFormat, argList); - } - - return hr; -} -#endif // FEATURE_PAL || !PLATFORM_UNIX -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI StringCchPrintf(LPTSTR pszDest, - size_t cchDest, - LPCTSTR pszFormat, - ...); - -Routine Description: - - This routine is a safer version of the C built-in function 'sprintf'. - The size of the destination buffer (in characters) is a parameter and - this function will not write past the end of this buffer and it will - ALWAYS null terminate the destination buffer (unless it is zero length). - - This function returns a hresult, and not a pointer. It returns a S_OK - if the string was printed without truncation and null terminated, otherwise - it will return a failure code. In failure cases it will return a truncated - version of the ideal result. - -Arguments: - - pszDest - destination string - - cchDest - size of destination buffer in characters - length must be sufficient to hold the resulting formatted - string, including the null terminator. - - pszFormat - format string which must be null terminated - - ... - additional parameters to be formatted according to - the format string - -Notes: - Behavior is undefined if destination, format strings or any arguments - strings overlap. - - pszDest and pszFormat should not be NULL. See StringCchPrintfEx if you - require the handling of NULL values. - -Return Value: - - S_OK - if there was sufficient space in the dest buffer for - the resultant string and it was null terminated. - - failure - you can use the macro HRESULT_CODE() to get a win32 error - code for all falure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the print operation - failed due to insufficient space. When this error occurs, - the destination buffer is modified to contain a truncated - version of the ideal result and is null terminated. This - is useful for situations where truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCchPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, ...); -STRSAFEAPI StringCchPrintfW(WCHAR* pszDest, size_t cchDest, const WCHAR* pszFormat, ...); -#ifdef UNICODE -#define StringCchPrintf StringCchPrintfW -#else -#define StringCchPrintf StringCchPrintfA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchPrintfA(char* pszDest, size_t cchDest, const char* pszFormat, ...) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - va_list argList; - - va_start(argList, pszFormat); - - hr = StringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList); - - va_end(argList); - } - - return hr; -} - -#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX) -STRSAFEAPI StringCchPrintfW(WCHAR* pszDest, size_t cchDest, const WCHAR* pszFormat, ...) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - va_list argList; - - va_start(argList, pszFormat); - - hr = StringVPrintfWorkerW(pszDest, cchDest, pszFormat, argList); - - va_end(argList); - } - - return hr; -} -#endif // FEATURE_PAL || !PLATFORM_UNIX -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI StringCbPrintf(LPTSTR pszDest, - size_t cbDest, - LPCTSTR pszFormat, - ...); - -Routine Description: - - This routine is a safer version of the C built-in function 'sprintf'. - The size of the destination buffer (in bytes) is a parameter and - this function will not write past the end of this buffer and it will - ALWAYS null terminate the destination buffer (unless it is zero length). - - This function returns a hresult, and not a pointer. It returns a S_OK - if the string was printed without truncation and null terminated, otherwise - it will return a failure code. In failure cases it will return a truncated - version of the ideal result. - -Arguments: - - pszDest - destination string - - cbDest - size of destination buffer in bytes - length must be sufficient to hold the resulting formatted - string, including the null terminator. - - pszFormat - format string which must be null terminated - - ... - additional parameters to be formatted according to - the format string - -Notes: - Behavior is undefined if destination, format strings or any arguments - strings overlap. - - pszDest and pszFormat should not be NULL. See StringCbPrintfEx if you - require the handling of NULL values. - - -Return Value: - - S_OK - if there was sufficient space in the dest buffer for - the resultant string and it was null terminated. - - failure - you can use the macro HRESULT_CODE() to get a win32 error - code for all falure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the print operation - failed due to insufficient space. When this error occurs, - the destination buffer is modified to contain a truncated - version of the ideal result and is null terminated. This - is useful for situations where truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCbPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, ...); -STRSAFEAPI StringCbPrintfW(WCHAR* pszDest, size_t cbDest, const WCHAR* pszFormat, ...); -#ifdef UNICODE -#define StringCbPrintf StringCbPrintfW -#else -#define StringCbPrintf StringCbPrintfA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, ...) -{ - HRESULT hr; - size_t cchDest; - - cchDest = cbDest / sizeof(char); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - va_list argList; - - va_start(argList, pszFormat); - - hr = StringVPrintfWorkerA(pszDest, cchDest, pszFormat, argList); - - va_end(argList); - } - - return hr; -} - -#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX) -STRSAFEAPI StringCbPrintfW(WCHAR* pszDest, size_t cbDest, const WCHAR* pszFormat, ...) -{ - HRESULT hr; - size_t cchDest; - - cchDest = cbDest / sizeof(WCHAR); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - va_list argList; - - va_start(argList, pszFormat); - - hr = StringVPrintfWorkerW(pszDest, cchDest, pszFormat, argList); - - va_end(argList); - } - - return hr; -} -#endif // FEATURE_PAL || !PLATFORM_UNIX -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI StringCchPrintfEx(LPTSTR pszDest, - size_t cchDest, - LPTSTR* ppszDestEnd, - size_t* pcchRemaining, - DWORD dwFlags, - LPCTSTR pszFormat, - ...); - -Routine Description: - - This routine is a safer version of the C built-in function 'sprintf' with - some additional parameters. In addition to functionality provided by - StringCchPrintf, this routine also returns a pointer to the end of the - destination string and the number of characters left in the destination string - including the null terminator. The flags parameter allows additional controls. - -Arguments: - - pszDest - destination string - - cchDest - size of destination buffer in characters. - length must be sufficient to contain the resulting - formatted string plus the null terminator. - - ppszDestEnd - if ppszDestEnd is non-null, the function will return a - pointer to the end of the destination string. If the - function printed any data, the result will point to the - null termination character - - pcchRemaining - if pcchRemaining is non-null, the function will return - the number of characters left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")) - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. This will overwrite any truncated - string returned when the failure is - STRSAFE_E_INSUFFICIENT_BUFFER - - STRSAFE_NO_TRUNCATION / - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. This will overwrite any truncated string - returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER. - - pszFormat - format string which must be null terminated - - ... - additional parameters to be formatted according to - the format string - -Notes: - Behavior is undefined if destination, format strings or any arguments - strings overlap. - - pszDest and pszFormat should not be NULL unless the STRSAFE_IGNORE_NULLS - flag is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and - pszFormat may be NULL. An error may still be returned even though NULLS - are ignored due to insufficient space. - -Return Value: - - S_OK - if there was source data and it was all concatenated and the - resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 error - code for all falure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the print operation - failed due to insufficient space. When this error occurs, - the destination buffer is modified to contain a truncated - version of the ideal result and is null terminated. This - is useful for situations where truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCchPrintfExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, ...); -STRSAFEAPI StringCchPrintfExW(WCHAR* pszDest, size_t cchDest, WCHAR** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const WCHAR* pszFormat, ...); -#ifdef UNICODE -#define StringCchPrintfEx StringCchPrintfExW -#else -#define StringCchPrintfEx StringCchPrintfExA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchPrintfExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, ...) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - va_list argList; - - // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1 - cbDest = cchDest * sizeof(char); - va_start(argList, pszFormat); - - hr = StringVPrintfExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, argList); - - va_end(argList); - } - - return hr; -} - -#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX) -STRSAFEAPI StringCchPrintfExW(WCHAR* pszDest, size_t cchDest, WCHAR** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const WCHAR* pszFormat, ...) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - va_list argList; - - // safe to multiply cchDest * sizeof(WCHAR) since cchDest < STRSAFE_MAX_CCH and sizeof(WCHAR) is 2 - cbDest = cchDest * sizeof(WCHAR); - va_start(argList, pszFormat); - - hr = StringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, argList); - - va_end(argList); - } - - return hr; -} -#endif // FEATURE_PAL || !PLATFORM_UNIX -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI StringCbPrintfEx(LPTSTR pszDest, - size_t cbDest, - LPTSTR* ppszDestEnd, - size_t* pcbRemaining, - DWORD dwFlags, - LPCTSTR pszFormat, - ...); - -Routine Description: - - This routine is a safer version of the C built-in function 'sprintf' with - some additional parameters. In addition to functionality provided by - StringCbPrintf, this routine also returns a pointer to the end of the - destination string and the number of bytes left in the destination string - including the null terminator. The flags parameter allows additional controls. - -Arguments: - - pszDest - destination string - - cbDest - size of destination buffer in bytes. - length must be sufficient to contain the resulting - formatted string plus the null terminator. - - ppszDestEnd - if ppszDestEnd is non-null, the function will return a - pointer to the end of the destination string. If the - function printed any data, the result will point to the - null termination character - - pcbRemaining - if pcbRemaining is non-null, the function will return - the number of bytes left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")) - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. This will overwrite any truncated - string returned when the failure is - STRSAFE_E_INSUFFICIENT_BUFFER - - STRSAFE_NO_TRUNCATION / - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. This will overwrite any truncated string - returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER. - - pszFormat - format string which must be null terminated - - ... - additional parameters to be formatted according to - the format string - -Notes: - Behavior is undefined if destination, format strings or any arguments - strings overlap. - - pszDest and pszFormat should not be NULL unless the STRSAFE_IGNORE_NULLS - flag is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and - pszFormat may be NULL. An error may still be returned even though NULLS - are ignored due to insufficient space. - -Return Value: - - S_OK - if there was source data and it was all concatenated and the - resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 error - code for all falure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the print operation - failed due to insufficient space. When this error occurs, - the destination buffer is modified to contain a truncated - version of the ideal result and is null terminated. This - is useful for situations where truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCbPrintfExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const char* pszFormat, ...); -STRSAFEAPI StringCbPrintfExW(WCHAR* pszDest, size_t cbDest, WCHAR** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const WCHAR* pszFormat, ...); -#ifdef UNICODE -#define StringCbPrintfEx StringCbPrintfExW -#else -#define StringCbPrintfEx StringCbPrintfExA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbPrintfExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const char* pszFormat, ...) -{ - HRESULT hr; - size_t cchDest; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(char); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - va_list argList; - - va_start(argList, pszFormat); - - hr = StringVPrintfExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags, pszFormat, argList); - - va_end(argList); - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1 - *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char)); - } - } - - return hr; -} - -#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX) -STRSAFEAPI StringCbPrintfExW(WCHAR* pszDest, size_t cbDest, WCHAR** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const WCHAR* pszFormat, ...) -{ - HRESULT hr; - size_t cchDest; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(WCHAR); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - va_list argList; - - va_start(argList, pszFormat); - - hr = StringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags, pszFormat, argList); - - va_end(argList); - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(WCHAR) since cchRemaining < STRSAFE_MAX_CCH and sizeof(WCHAR) is 2 - *pcbRemaining = (cchRemaining * sizeof(WCHAR)) + (cbDest % sizeof(WCHAR)); - } - } - - return hr; -} -#endif // FEATURE_PAL || !PLATFORM_UNIX -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - -STDAPI StringCchVPrintfEx(LPTSTR pszDest, - size_t cchDest, - LPTSTR* ppszDestEnd, - size_t* pcchRemaining, - DWORD dwFlags, - LPCTSTR pszFormat, - va_list argList); - -Routine Description: - - This routine is a safer version of the C built-in function 'vsprintf' with - some additional parameters. In addition to functionality provided by - StringCchVPrintf, this routine also returns a pointer to the end of the - destination string and the number of characters left in the destination string - including the null terminator. The flags parameter allows additional controls. - -Arguments: - - pszDest - destination string - - cchDest - size of destination buffer in characters. - length must be sufficient to contain the resulting - formatted string plus the null terminator. - - ppszDestEnd - if ppszDestEnd is non-null, the function will return a - pointer to the end of the destination string. If the - function printed any data, the result will point to the - null termination character - - pcchRemaining - if pcchRemaining is non-null, the function will return - the number of characters left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")) - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. This will overwrite any truncated - string returned when the failure is - STRSAFE_E_INSUFFICIENT_BUFFER - - STRSAFE_NO_TRUNCATION / - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. This will overwrite any truncated string - returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER. - - pszFormat - format string which must be null terminated - - argList - va_list from the variable arguments according to the - stdarg.h convention - -Notes: - Behavior is undefined if destination, format strings or any arguments - strings overlap. - - pszDest and pszFormat should not be NULL unless the STRSAFE_IGNORE_NULLS - flag is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and - pszFormat may be NULL. An error may still be returned even though NULLS - are ignored due to insufficient space. - -Return Value: - - S_OK - if there was source data and it was all concatenated and the - resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 error - code for all falure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the print operation - failed due to insufficient space. When this error occurs, - the destination buffer is modified to contain a truncated - version of the ideal result and is null terminated. This - is useful for situations where truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCchVPrintfExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList); -STRSAFEAPI StringCchVPrintfExW(WCHAR* pszDest, size_t cchDest, WCHAR** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const WCHAR* pszFormat, va_list argList); -#ifdef UNICODE -#define StringCchVPrintfEx StringCchVPrintfExW -#else -#define StringCchVPrintfEx StringCchVPrintfExA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCchVPrintfExA(char* pszDest, size_t cchDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - - // safe to multiply cchDest * sizeof(char) since cchDest < STRSAFE_MAX_CCH and sizeof(char) is 1 - cbDest = cchDest * sizeof(char); - - hr = StringVPrintfExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, argList); - } - - return hr; -} - -#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX) -STRSAFEAPI StringCchVPrintfExW(WCHAR* pszDest, size_t cchDest, WCHAR** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const WCHAR* pszFormat, va_list argList) -{ - HRESULT hr; - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - size_t cbDest; - - // safe to multiply cchDest * sizeof(WCHAR) since cchDest < STRSAFE_MAX_CCH and sizeof(WCHAR) is 2 - cbDest = cchDest * sizeof(WCHAR); - - hr = StringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, pcchRemaining, dwFlags, pszFormat, argList); - } - - return hr; -} -#endif // FEATURE_PAL || !PLATFORM_UNIX -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CCH_FUNCTIONS - - -#ifndef STRSAFE_NO_CB_FUNCTIONS -/*++ - -STDAPI StringCbVPrintfEx(LPTSTR pszDest, - size_t cbDest, - LPTSTR* ppszDestEnd, - size_t* pcbRemaining, - DWORD dwFlags, - LPCTSTR pszFormat, - va_list argList); - -Routine Description: - - This routine is a safer version of the C built-in function 'vsprintf' with - some additional parameters. In addition to functionality provided by - StringCbVPrintf, this routine also returns a pointer to the end of the - destination string and the number of characters left in the destination string - including the null terminator. The flags parameter allows additional controls. - -Arguments: - - pszDest - destination string - - cbDest - size of destination buffer in bytes. - length must be sufficient to contain the resulting - formatted string plus the null terminator. - - ppszDestEnd - if ppszDestEnd is non-null, the function will return - a pointer to the end of the destination string. If the - function printed any data, the result will point to the - null termination character - - pcbRemaining - if pcbRemaining is non-null, the function will return - the number of bytes left in the destination string, - including the null terminator - - dwFlags - controls some details of the string copy: - - STRSAFE_FILL_BEHIND_NULL - if the function succeeds, the low byte of dwFlags will be - used to fill the uninitialize part of destination buffer - behind the null terminator - - STRSAFE_IGNORE_NULLS - treat NULL string pointers like empty strings (TEXT("")) - - STRSAFE_FILL_ON_FAILURE - if the function fails, the low byte of dwFlags will be - used to fill all of the destination buffer, and it will - be null terminated. This will overwrite any truncated - string returned when the failure is - STRSAFE_E_INSUFFICIENT_BUFFER - - STRSAFE_NO_TRUNCATION / - STRSAFE_NULL_ON_FAILURE - if the function fails, the destination buffer will be set - to the empty string. This will overwrite any truncated string - returned when the failure is STRSAFE_E_INSUFFICIENT_BUFFER. - - pszFormat - format string which must be null terminated - - argList - va_list from the variable arguments according to the - stdarg.h convention - -Notes: - Behavior is undefined if destination, format strings or any arguments - strings overlap. - - pszDest and pszFormat should not be NULL unless the STRSAFE_IGNORE_NULLS - flag is specified. If STRSAFE_IGNORE_NULLS is passed, both pszDest and - pszFormat may be NULL. An error may still be returned even though NULLS - are ignored due to insufficient space. - -Return Value: - - S_OK - if there was source data and it was all concatenated and the - resultant dest string was null terminated - - failure - you can use the macro HRESULT_CODE() to get a win32 error - code for all falure cases - - STRSAFE_E_INSUFFICIENT_BUFFER / - HRESULT_CODE(hr) == ERROR_INSUFFICIENT_BUFFER - - this return value is an indication that the print operation - failed due to insufficient space. When this error occurs, - the destination buffer is modified to contain a truncated - version of the ideal result and is null terminated. This - is useful for situations where truncation is ok. - - It is strongly recommended to use the SUCCEEDED() / FAILED() macros to test the - return value of this function - ---*/ - -STRSAFEAPI StringCbVPrintfExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList); -STRSAFEAPI StringCbVPrintfExW(WCHAR* pszDest, size_t cbDest, WCHAR** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const WCHAR* pszFormat, va_list argList); -#ifdef UNICODE -#define StringCbVPrintfEx StringCbVPrintfExW -#else -#define StringCbVPrintfEx StringCbVPrintfExA -#endif // !UNICODE - -#ifdef STRSAFE_INLINE -STRSAFEAPI StringCbVPrintfExA(char* pszDest, size_t cbDest, char** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList) -{ - HRESULT hr; - size_t cchDest; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(char); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringVPrintfExWorkerA(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags, pszFormat, argList); - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(char) since cchRemaining < STRSAFE_MAX_CCH and sizeof(char) is 1 - *pcbRemaining = (cchRemaining * sizeof(char)) + (cbDest % sizeof(char)); - } - } - - return hr; -} - -#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX) -STRSAFEAPI StringCbVPrintfExW(WCHAR* pszDest, size_t cbDest, WCHAR** ppszDestEnd, size_t* pcbRemaining, unsigned long dwFlags, const WCHAR* pszFormat, va_list argList) -{ - HRESULT hr; - size_t cchDest; - size_t cchRemaining = 0; - - cchDest = cbDest / sizeof(WCHAR); - - if (cchDest > STRSAFE_MAX_CCH) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = StringVPrintfExWorkerW(pszDest, cchDest, cbDest, ppszDestEnd, &cchRemaining, dwFlags, pszFormat, argList); - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (pcbRemaining) - { - // safe to multiply cchRemaining * sizeof(WCHAR) since cchRemaining < STRSAFE_MAX_CCH and sizeof(WCHAR) is 2 - *pcbRemaining = (cchRemaining * sizeof(WCHAR)) + (cbDest % sizeof(WCHAR)); - } - } - - return hr; -} -#endif // FEATURE_PAL || !PLATFORM_UNIX -#endif // STRSAFE_INLINE -#endif // !STRSAFE_NO_CB_FUNCTIONS - - -#ifndef STRSAFE_NO_CCH_FUNCTIONS -/*++ - STDAPI StringCchGets(LPTSTR pszDest, size_t cchDest); @@ -5543,394 +4421,6 @@ STRSAFEAPI StringCatNExWorkerW(WCHAR* pszDest, size_t cchDest, size_t cbDest, co } #endif // FEATURE_PAL || !PLATFORM_UNIX -STRSAFEAPI StringVPrintfWorkerA(char* pszDest, size_t cchDest, const char* pszFormat, va_list argList) -{ - HRESULT hr = S_OK; - - if (cchDest == 0) - { - // can not null terminate a zero-byte dest buffer - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - int iRet; - size_t cchMax; - - // leave the last space for the null terminator - cchMax = cchDest - 1; - - iRet = _vsnprintf(pszDest, cchMax, pszFormat, argList); - // ASSERT((iRet < 0) || (((size_t)iRet) <= cchMax)); - - if ((iRet < 0) || (((size_t)iRet) > cchMax)) - { - // need to null terminate the string - pszDest += cchMax; - *pszDest = '\0'; - - // we have truncated pszDest - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - else if (((size_t)iRet) == cchMax) - { - // need to null terminate the string - pszDest += cchMax; - *pszDest = '\0'; - } - } - - return hr; -} - -#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX) -STRSAFEAPI StringVPrintfWorkerW(WCHAR* pszDest, size_t cchDest, const WCHAR* pszFormat, va_list argList) -{ - HRESULT hr = S_OK; - - if (cchDest == 0) - { - // can not null terminate a zero-byte dest buffer - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - int iRet; - size_t cchMax; - - // leave the last space for the null terminator - cchMax = cchDest - 1; - - iRet = _vsnwprintf(pszDest, cchMax, pszFormat, argList); - // ASSERT((iRet < 0) || (((size_t)iRet) <= cchMax)); - - if ((iRet < 0) || (((size_t)iRet) > cchMax)) - { - // need to null terminate the string - pszDest += cchMax; - *pszDest = L'\0'; - - // we have truncated pszDest - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - else if (((size_t)iRet) == cchMax) - { - // need to null terminate the string - pszDest += cchMax; - *pszDest = L'\0'; - } - } - - return hr; -} -#endif // FEATURE_PAL || !PLATFORM_UNIX - -STRSAFEAPI StringVPrintfExWorkerA(char* pszDest, size_t cchDest, size_t cbDest, char** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const char* pszFormat, va_list argList) -{ - HRESULT hr = S_OK; - char* pszDestEnd = pszDest; - size_t cchRemaining = 0; - - // ASSERT(cbDest == (cchDest * sizeof(char)) || - // cbDest == (cchDest * sizeof(char)) + (cbDest % sizeof(char))); - - // only accept valid flags - if (dwFlags & (~STRSAFE_VALID_FLAGS)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - if (dwFlags & STRSAFE_IGNORE_NULLS) - { - if (pszDest == NULL) - { - if ((cchDest != 0) || (cbDest != 0)) - { - // NULL pszDest and non-zero cchDest/cbDest is invalid - hr = STRSAFE_E_INVALID_PARAMETER; - } - } - - if (pszFormat == NULL) - { - pszFormat = ""; - } - } - - if (SUCCEEDED(hr)) - { - if (cchDest == 0) - { - pszDestEnd = pszDest; - cchRemaining = 0; - - // only fail if there was actually a non-empty format string - if (*pszFormat != '\0') - { - if (pszDest == NULL) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - } - } - else - { - int iRet; - size_t cchMax; - - // leave the last space for the null terminator - cchMax = cchDest - 1; - - iRet = _vsnprintf(pszDest, cchMax, pszFormat, argList); - // ASSERT((iRet < 0) || (((size_t)iRet) <= cchMax)); - - if ((iRet < 0) || (((size_t)iRet) > cchMax)) - { - // we have truncated pszDest - pszDestEnd = pszDest + cchMax; - cchRemaining = 1; - - // need to null terminate the string - *pszDestEnd = '\0'; - - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - else if (((size_t)iRet) == cchMax) - { - // string fit perfectly - pszDestEnd = pszDest + cchMax; - cchRemaining = 1; - - // need to null terminate the string - *pszDestEnd = '\0'; - } - else if (((size_t)iRet) < cchMax) - { - // there is extra room - pszDestEnd = pszDest + iRet; - cchRemaining = cchDest - iRet; - - if (dwFlags & STRSAFE_FILL_BEHIND_NULL) - { - memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(char)) + (cbDest % sizeof(char))); - } - } - } - } - } - - if (FAILED(hr)) - { - if (pszDest) - { - if (dwFlags & STRSAFE_FILL_ON_FAILURE) - { - memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest); - - if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - } - else if (cchDest > 0) - { - pszDestEnd = pszDest + cchDest - 1; - cchRemaining = 1; - - // null terminate the end of the string - *pszDestEnd = '\0'; - } - } - - if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) - { - if (cchDest > 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - // null terminate the beginning of the string - *pszDestEnd = '\0'; - } - } - } - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (ppszDestEnd) - { - *ppszDestEnd = pszDestEnd; - } - - if (pcchRemaining) - { - *pcchRemaining = cchRemaining; - } - } - - return hr; -} - -#if defined(FEATURE_PAL) || !defined(PLATFORM_UNIX) -STRSAFEAPI StringVPrintfExWorkerW(WCHAR* pszDest, size_t cchDest, size_t cbDest, WCHAR** ppszDestEnd, size_t* pcchRemaining, unsigned long dwFlags, const WCHAR* pszFormat, va_list argList) -{ - HRESULT hr = S_OK; - WCHAR* pszDestEnd = pszDest; - size_t cchRemaining = 0; - - // ASSERT(cbDest == (cchDest * sizeof(WCHAR)) || - // cbDest == (cchDest * sizeof(WCHAR)) + (cbDest % sizeof(WCHAR))); - - // only accept valid flags - if (dwFlags & (~STRSAFE_VALID_FLAGS)) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - if (dwFlags & STRSAFE_IGNORE_NULLS) - { - if (pszDest == NULL) - { - if ((cchDest != 0) || (cbDest != 0)) - { - // NULL pszDest and non-zero cchDest/cbDest is invalid - hr = STRSAFE_E_INVALID_PARAMETER; - } - } - - if (pszFormat == NULL) - { - pszFormat = u""; - } - } - - if (SUCCEEDED(hr)) - { - if (cchDest == 0) - { - pszDestEnd = pszDest; - cchRemaining = 0; - - // only fail if there was actually a non-empty format string - if (*pszFormat != L'\0') - { - if (pszDest == NULL) - { - hr = STRSAFE_E_INVALID_PARAMETER; - } - else - { - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - } - } - else - { - int iRet; - size_t cchMax; - - // leave the last space for the null terminator - cchMax = cchDest - 1; - - iRet = _vsnwprintf(pszDest, cchMax, pszFormat, argList); - // ASSERT((iRet < 0) || (((size_t)iRet) <= cchMax)); - - if ((iRet < 0) || (((size_t)iRet) > cchMax)) - { - // we have truncated pszDest - pszDestEnd = pszDest + cchMax; - cchRemaining = 1; - - // need to null terminate the string - *pszDestEnd = L'\0'; - - hr = STRSAFE_E_INSUFFICIENT_BUFFER; - } - else if (((size_t)iRet) == cchMax) - { - // string fit perfectly - pszDestEnd = pszDest + cchMax; - cchRemaining = 1; - - // need to null terminate the string - *pszDestEnd = L'\0'; - } - else if (((size_t)iRet) < cchMax) - { - // there is extra room - pszDestEnd = pszDest + iRet; - cchRemaining = cchDest - iRet; - - if (dwFlags & STRSAFE_FILL_BEHIND_NULL) - { - memset(pszDestEnd + 1, STRSAFE_GET_FILL_PATTERN(dwFlags), ((cchRemaining - 1) * sizeof(WCHAR)) + (cbDest % sizeof(WCHAR))); - } - } - } - } - } - - if (FAILED(hr)) - { - if (pszDest) - { - if (dwFlags & STRSAFE_FILL_ON_FAILURE) - { - memset(pszDest, STRSAFE_GET_FILL_PATTERN(dwFlags), cbDest); - - if (STRSAFE_GET_FILL_PATTERN(dwFlags) == 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - } - else if (cchDest > 0) - { - pszDestEnd = pszDest + cchDest - 1; - cchRemaining = 1; - - // null terminate the end of the string - *pszDestEnd = L'\0'; - } - } - - if (dwFlags & (STRSAFE_NULL_ON_FAILURE | STRSAFE_NO_TRUNCATION)) - { - if (cchDest > 0) - { - pszDestEnd = pszDest; - cchRemaining = cchDest; - - // null terminate the beginning of the string - *pszDestEnd = L'\0'; - } - } - } - } - - if (SUCCEEDED(hr) || (hr == STRSAFE_E_INSUFFICIENT_BUFFER)) - { - if (ppszDestEnd) - { - *ppszDestEnd = pszDestEnd; - } - - if (pcchRemaining) - { - *pcchRemaining = cchRemaining; - } - } - - return hr; -} -#endif // FEATURE_PAL || !PLATFORM_UNIX - STRSAFEAPI StringLengthWorkerA(const char* psz, size_t cchMax, size_t* pcch) { HRESULT hr = S_OK; |