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: sprintf_s function 123d58139fSopenharmony_ci * Create: 2014-02-25 133d58139fSopenharmony_ci */ 143d58139fSopenharmony_ci 153d58139fSopenharmony_ci#include "securec.h" 163d58139fSopenharmony_ci 173d58139fSopenharmony_ci/* 183d58139fSopenharmony_ci * <FUNCTION DESCRIPTION> 193d58139fSopenharmony_ci * The sprintf_s function is equivalent to the sprintf function 203d58139fSopenharmony_ci * except for the parameter destMax and the explicit runtime-constraints violation 213d58139fSopenharmony_ci * The sprintf_s function formats and stores a series of characters and values 223d58139fSopenharmony_ci * in strDest. Each argument (if any) is converted and output according to 233d58139fSopenharmony_ci * the corresponding format specification in format. The format consists of 243d58139fSopenharmony_ci * ordinary characters and has the same form and function as the format argument 253d58139fSopenharmony_ci * for printf. A null character is appended after the last character written. 263d58139fSopenharmony_ci * If copying occurs between strings that overlap, the behavior is undefined. 273d58139fSopenharmony_ci * 283d58139fSopenharmony_ci * <INPUT PARAMETERS> 293d58139fSopenharmony_ci * strDest Storage location for output. 303d58139fSopenharmony_ci * destMax Maximum number of characters to store. 313d58139fSopenharmony_ci * format Format-control string. 323d58139fSopenharmony_ci * ... Optional arguments 333d58139fSopenharmony_ci * 343d58139fSopenharmony_ci * <OUTPUT PARAMETERS> 353d58139fSopenharmony_ci * strDest is updated 363d58139fSopenharmony_ci * 373d58139fSopenharmony_ci * <RETURN VALUE> 383d58139fSopenharmony_ci * return the number of bytes stored in strDest, not counting the terminating null character. 393d58139fSopenharmony_ci * return -1 if an error occurred. 403d58139fSopenharmony_ci * 413d58139fSopenharmony_ci * If there is a runtime-constraint violation, strDest[0] will be set to the '\0' when strDest and destMax valid 423d58139fSopenharmony_ci */ 433d58139fSopenharmony_ciint sprintf_s(char *strDest, size_t destMax, const char *format, ...) 443d58139fSopenharmony_ci{ 453d58139fSopenharmony_ci int ret; /* If initialization causes e838 */ 463d58139fSopenharmony_ci va_list argList; 473d58139fSopenharmony_ci 483d58139fSopenharmony_ci va_start(argList, format); 493d58139fSopenharmony_ci ret = vsprintf_s(strDest, destMax, format, argList); 503d58139fSopenharmony_ci va_end(argList); 513d58139fSopenharmony_ci (void)argList; /* To clear e438 last value assigned not used , the compiler will optimize this code */ 523d58139fSopenharmony_ci 533d58139fSopenharmony_ci return ret; 543d58139fSopenharmony_ci} 553d58139fSopenharmony_ci#if SECUREC_EXPORT_KERNEL_SYMBOL 563d58139fSopenharmony_ciEXPORT_SYMBOL(sprintf_s); 573d58139fSopenharmony_ci#endif 583d58139fSopenharmony_ci 59