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 vwscanf_s function is the wide-character equivalent of the vscanf_s function
21 * The vwscanf_s function is the wide-character version of vscanf_s. The
22 * function reads data from the standard input stream stdin and writes the
23 * data into the location that's given by argument. Each argument must be a
24 * pointer to a variable of a type that corresponds to a type specifier in
25 * format. If copying occurs between strings that overlap, the behavior is
26 * undefined.
27 *
28 * <INPUT PARAMETERS>
29 * format Format control string.
30 * arglist pointer to list of arguments
31 *
32 * <OUTPUT PARAMETERS>
33 * arglist the converted value stored in user assigned address
34 *
35 * <RETURN VALUE>
36 * Returns the number of fields successfully converted and assigned;
37 * the return value does not include fields that were read but not assigned.
38 * A return value of 0 indicates that no fields were assigned.
39 * return -1 if an error occurs.
40 *******************************************************************************
41 */
vwscanf_s(const wchar_t * format,va_list arglist)42 int vwscanf_s(const wchar_t *format, va_list arglist)
43 {
44 int retVal; /* If initialization causes e838 */
45 SecFileStream fStr = SECUREC_INIT_SEC_FILE_STREAM;
46
47 fStr.pf = stdin;
48 if (format == NULL || fStr.pf == NULL) {
49 SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s");
50 return SECUREC_SCANF_EINVAL;
51 }
52
53 fStr.flag = SECUREC_FROM_STDIN_FLAG;
54
55 SECUREC_LOCK_STDIN(0, fStr.pf);
56
57 retVal = SecInputSW(&fStr, format, arglist);
58
59 SECUREC_UNLOCK_STDIN(0, fStr.pf);
60
61 if (retVal < 0) {
62 SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s");
63 return SECUREC_SCANF_EINVAL;
64 }
65
66 return retVal;
67 }
68
69
70