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: vfwscanf_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 "secinput.h" 203d58139fSopenharmony_ci 213d58139fSopenharmony_ci/* 223d58139fSopenharmony_ci * <FUNCTION DESCRIPTION> 233d58139fSopenharmony_ci * The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function 243d58139fSopenharmony_ci * The vfwscanf_s function reads data from the current position of stream into 253d58139fSopenharmony_ci * the locations given by argument (if any). Each argument must be a pointer 263d58139fSopenharmony_ci * to a variable of a type that corresponds to a type specifier in format. 273d58139fSopenharmony_ci * format controls the interpretation of the input fields and has the same form 283d58139fSopenharmony_ci * and function as the format argument for scanf. 293d58139fSopenharmony_ci * 303d58139fSopenharmony_ci * <INPUT PARAMETERS> 313d58139fSopenharmony_ci * stream Pointer to FILE structure. 323d58139fSopenharmony_ci * format Format control string, see Format Specifications. 333d58139fSopenharmony_ci * argList pointer to list of arguments 343d58139fSopenharmony_ci * 353d58139fSopenharmony_ci * <OUTPUT PARAMETERS> 363d58139fSopenharmony_ci * argList the converted value stored in user assigned address 373d58139fSopenharmony_ci * 383d58139fSopenharmony_ci * <RETURN VALUE> 393d58139fSopenharmony_ci * Each of these functions returns the number of fields successfully converted 403d58139fSopenharmony_ci * and assigned; the return value does not include fields that were read but 413d58139fSopenharmony_ci * not assigned. A return value of 0 indicates that no fields were assigned. 423d58139fSopenharmony_ci * return -1 if an error occurs. 433d58139fSopenharmony_ci */ 443d58139fSopenharmony_ciint vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList) 453d58139fSopenharmony_ci{ 463d58139fSopenharmony_ci int retVal; /* If initialization causes e838 */ 473d58139fSopenharmony_ci SecFileStream fStr; 483d58139fSopenharmony_ci 493d58139fSopenharmony_ci if (stream == NULL || format == NULL) { 503d58139fSopenharmony_ci SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s"); 513d58139fSopenharmony_ci return SECUREC_SCANF_EINVAL; 523d58139fSopenharmony_ci } 533d58139fSopenharmony_ci if (stream == SECUREC_STREAM_STDIN) { 543d58139fSopenharmony_ci return vwscanf_s(format, argList); 553d58139fSopenharmony_ci } 563d58139fSopenharmony_ci 573d58139fSopenharmony_ci SECUREC_LOCK_FILE(stream); 583d58139fSopenharmony_ci SECUREC_FILE_STREAM_FROM_FILE(&fStr, stream); 593d58139fSopenharmony_ci retVal = SecInputSW(&fStr, format, argList); 603d58139fSopenharmony_ci SECUREC_UNLOCK_FILE(stream); 613d58139fSopenharmony_ci if (retVal < 0) { 623d58139fSopenharmony_ci SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s"); 633d58139fSopenharmony_ci return SECUREC_SCANF_EINVAL; 643d58139fSopenharmony_ci } 653d58139fSopenharmony_ci return retVal; 663d58139fSopenharmony_ci} 673d58139fSopenharmony_ci 68