1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. All rights reserved.
3 * Licensed under Mulan PSL v2.
4 * You can use this software according to the terms and conditions of the Mulan PSL v2.
5 * You may obtain a copy of Mulan PSL v2 at:
6 * http://license.coscl.org.cn/MulanPSL2
7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10 * See the Mulan PSL v2 for more details.
11 * Description: vswprintf_s function
12 * Author: lishunda
13 * Create: 2014-02-25
14 */
15
16 #ifndef SECUREC_FOR_WCHAR
17 #define SECUREC_FOR_WCHAR
18 #endif
19
20 #include "secureprintoutput.h"
21
22 /*
23 * <FUNCTION DESCRIPTION>
24 * The vswprintf_s function is the wide-character equivalent of the vsprintf_s function
25 *
26 * <INPUT PARAMETERS>
27 * strDest Storage location for the output.
28 * destMax Maximum number of characters to store
29 * format Format specification.
30 * argList pointer to list of arguments
31 *
32 * <OUTPUT PARAMETERS>
33 * strDest is updated
34 *
35 * <RETURN VALUE>
36 * return the number of wide characters stored in strDest, not counting the terminating null wide character.
37 * return -1 if an error occurred.
38 *
39 * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
40 */
vswprintf_s(wchar_t * strDest,size_t destMax,const wchar_t * format,va_list argList)41 int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList)
42 {
43 int retVal; /* If initialization causes e838 */
44 if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, SECUREC_WCHAR_STRING_MAX_LEN)) {
45 SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_WCHAR_STRING_MAX_LEN);
46 SECUREC_ERROR_INVALID_PARAMTER("vswprintf_s");
47 return -1;
48 }
49
50 retVal = SecVswprintfImpl(strDest, destMax, format, argList);
51 if (retVal < 0) {
52 strDest[0] = L'\0';
53 if (retVal == SECUREC_PRINTF_TRUNCATE) {
54 /* Buffer too small */
55 SECUREC_ERROR_INVALID_RANGE("vswprintf_s");
56 }
57 SECUREC_ERROR_INVALID_PARAMTER("vswprintf_s");
58 return -1;
59 }
60
61 return retVal;
62 }
63
64