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