13d58139fSopenharmony_ci/*
23d58139fSopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2014-2021. All rights reserved.
33d58139fSopenharmony_ci * Licensed under Mulan PSL v2.
43d58139fSopenharmony_ci * You can use this software according to the terms and conditions of the Mulan PSL v2.
53d58139fSopenharmony_ci * You may obtain a copy of Mulan PSL v2 at:
63d58139fSopenharmony_ci *          http://license.coscl.org.cn/MulanPSL2
73d58139fSopenharmony_ci * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
83d58139fSopenharmony_ci * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
93d58139fSopenharmony_ci * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
103d58139fSopenharmony_ci * See the Mulan PSL v2 for more details.
113d58139fSopenharmony_ci * Description: vswprintf_s  function
123d58139fSopenharmony_ci * Create: 2014-02-25
133d58139fSopenharmony_ci */
143d58139fSopenharmony_ci
153d58139fSopenharmony_ci#ifndef SECUREC_FOR_WCHAR
163d58139fSopenharmony_ci#define SECUREC_FOR_WCHAR
173d58139fSopenharmony_ci#endif
183d58139fSopenharmony_ci
193d58139fSopenharmony_ci#include "secureprintoutput.h"
203d58139fSopenharmony_ci
213d58139fSopenharmony_ci/*
223d58139fSopenharmony_ci * <FUNCTION DESCRIPTION>
233d58139fSopenharmony_ci *    The  vswprintf_s  function  is  the  wide-character  equivalent  of the vsprintf_s function
243d58139fSopenharmony_ci *
253d58139fSopenharmony_ci * <INPUT PARAMETERS>
263d58139fSopenharmony_ci *    strDest                  Storage location for the output.
273d58139fSopenharmony_ci *    destMax                  Maximum number of characters to store
283d58139fSopenharmony_ci *    format                   Format specification.
293d58139fSopenharmony_ci *    argList                  pointer to list of arguments
303d58139fSopenharmony_ci *
313d58139fSopenharmony_ci * <OUTPUT PARAMETERS>
323d58139fSopenharmony_ci *    strDest                 is updated
333d58139fSopenharmony_ci *
343d58139fSopenharmony_ci * <RETURN VALUE>
353d58139fSopenharmony_ci *    return  the number of wide characters stored in strDest, not  counting the terminating null wide character.
363d58139fSopenharmony_ci *    return -1  if an error occurred.
373d58139fSopenharmony_ci *
383d58139fSopenharmony_ci * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid
393d58139fSopenharmony_ci */
403d58139fSopenharmony_ciint vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList)
413d58139fSopenharmony_ci{
423d58139fSopenharmony_ci    int retVal;               /* If initialization causes  e838 */
433d58139fSopenharmony_ci    if (SECUREC_VSPRINTF_PARAM_ERROR(format, strDest, destMax, SECUREC_WCHAR_STRING_MAX_LEN)) {
443d58139fSopenharmony_ci        SECUREC_VSPRINTF_CLEAR_DEST(strDest, destMax, SECUREC_WCHAR_STRING_MAX_LEN);
453d58139fSopenharmony_ci        SECUREC_ERROR_INVALID_PARAMTER("vswprintf_s");
463d58139fSopenharmony_ci        return -1;
473d58139fSopenharmony_ci    }
483d58139fSopenharmony_ci
493d58139fSopenharmony_ci    retVal = SecVswprintfImpl(strDest, destMax, format, argList);
503d58139fSopenharmony_ci    if (retVal < 0) {
513d58139fSopenharmony_ci        strDest[0] = L'\0';
523d58139fSopenharmony_ci        if (retVal == SECUREC_PRINTF_TRUNCATE) {
533d58139fSopenharmony_ci            /* Buffer too small */
543d58139fSopenharmony_ci            SECUREC_ERROR_INVALID_RANGE("vswprintf_s");
553d58139fSopenharmony_ci        }
563d58139fSopenharmony_ci        SECUREC_ERROR_INVALID_PARAMTER("vswprintf_s");
573d58139fSopenharmony_ci        return -1;
583d58139fSopenharmony_ci    }
593d58139fSopenharmony_ci
603d58139fSopenharmony_ci    return retVal;
613d58139fSopenharmony_ci}
623d58139fSopenharmony_ci
63