1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2014-2021. 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: vfwscanf_s function
12 * Create: 2014-02-25
13 */
14
15 #ifndef SECUREC_FOR_WCHAR
16 #define SECUREC_FOR_WCHAR
17 #endif
18
19 #include "secinput.h"
20
21 /*
22 * <FUNCTION DESCRIPTION>
23 * The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function
24 * The vfwscanf_s function reads data from the current position of stream into
25 * the locations given by argument (if any). Each argument must be a pointer
26 * to a variable of a type that corresponds to a type specifier in format.
27 * format controls the interpretation of the input fields and has the same form
28 * and function as the format argument for scanf.
29 *
30 * <INPUT PARAMETERS>
31 * stream Pointer to FILE structure.
32 * format Format control string, see Format Specifications.
33 * argList pointer to list of arguments
34 *
35 * <OUTPUT PARAMETERS>
36 * argList the converted value stored in user assigned address
37 *
38 * <RETURN VALUE>
39 * Each of these functions returns the number of fields successfully converted
40 * and assigned; the return value does not include fields that were read but
41 * not assigned. A return value of 0 indicates that no fields were assigned.
42 * return -1 if an error occurs.
43 */
vfwscanf_s(FILE * stream,const wchar_t * format,va_list argList)44 int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList)
45 {
46 int retVal; /* If initialization causes e838 */
47 SecFileStream fStr;
48
49 if (stream == NULL || format == NULL) {
50 SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s");
51 return SECUREC_SCANF_EINVAL;
52 }
53 if (stream == SECUREC_STREAM_STDIN) {
54 return vwscanf_s(format, argList);
55 }
56
57 SECUREC_LOCK_FILE(stream);
58 SECUREC_FILE_STREAM_FROM_FILE(&fStr, stream);
59 retVal = SecInputSW(&fStr, format, argList);
60 SECUREC_UNLOCK_FILE(stream);
61 if (retVal < 0) {
62 SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s");
63 return SECUREC_SCANF_EINVAL;
64 }
65 return retVal;
66 }
67
68