1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "secinput.h"
17
18 /*******************************************************************************
19 * <FUNCTION DESCRIPTION>
20 * The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function
21 * The vfwscanf_s function reads data from the current position of stream into
22 * the locations given by argument (if any). Each argument must be a pointer
23 * to a variable of a type that corresponds to a type specifier in format.
24 * format controls the interpretation of the input fields and has the same form
25 * and function as the format argument for scanf; see scanf for a description
26 * of format.
27 *
28 * <INPUT PARAMETERS>
29 * stream Pointer to FILE structure.
30 * format Format control string, see Format Specifications.
31 * arglist pointer to list of arguments
32 *
33 * <OUTPUT PARAMETERS>
34 * arglist the converted value stored in user assigned address
35 *
36 * <RETURN VALUE>
37 * Each of these functions returns the number of fields successfully converted
38 * and assigned; the return value does not include fields that were read but
39 * not assigned. A return value of 0 indicates that no fields were assigned.
40 * return -1 if an error occurs.
41 *******************************************************************************
42 */
vfwscanf_s(FILE * stream,const wchar_t * format,va_list arglist)43 int vfwscanf_s(FILE *stream, const wchar_t *format, va_list arglist)
44 {
45 int retVal; /* If initialization causes e838 */
46 SecFileStream fStr = SECUREC_INIT_SEC_FILE_STREAM;
47
48 if ((stream == NULL) || (format == NULL)) {
49 SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s");
50 return SECUREC_SCANF_EINVAL;
51 }
52 if (stream == stdin) {
53 return vwscanf_s(format, arglist);
54 }
55
56 SECUREC_LOCK_FILE(stream);
57
58 fStr.pf = stream;
59 fStr.flag = SECUREC_FILE_STREAM_FLAG;
60 fStr.oriFilePos = SECUREC_UNINITIALIZED_FILE_POS;
61
62 retVal = SecInputSW(&fStr, format, arglist);
63 SECUREC_UNLOCK_FILE(stream);
64 if (retVal < 0) {
65 SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s");
66 return SECUREC_SCANF_EINVAL;
67 }
68 return retVal;
69 }
70
71
72