• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: vwscanf_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  vwscanf_s  function  is  the  wide-character  equivalent  of the vscanf_s function
24  *    The vwscanf_s function is the wide-character version of vscanf_s. The
25  *    function reads data from the standard input stream stdin and writes the
26  *    data into the location that's given by argument. Each argument  must be a
27  *    pointer to a variable of a type that corresponds to a type specifier in
28  *    format. If copying occurs between strings that overlap, the behavior is
29  *    undefined.
30  *
31  * <INPUT PARAMETERS>
32  *    format                 Format control string.
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  *    Returns the number of fields successfully converted and assigned;
40  *    the return value does not include fields that were read but not assigned.
41  *    A return value of 0 indicates that no fields were assigned.
42  *    return -1 if an error occurs.
43  */
vwscanf_s(const wchar_t * format,va_list argList)44 int vwscanf_s(const wchar_t *format, va_list argList)
45 {
46     int retVal;                 /* If initialization causes  e838 */
47     SecFileStream fStr;
48     SECUREC_FILE_STREAM_FROM_STDIN(&fStr);
49 #if SECUREC_ENABLE_SCANF_FILE
50     if (format == NULL || fStr.pf == NULL) {
51 #else
52     if (format == NULL) {
53 #endif
54         SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s");
55         return SECUREC_SCANF_EINVAL;
56     }
57 
58 #if SECUREC_ENABLE_SCANF_FILE
59     SECUREC_LOCK_STDIN(0, fStr.pf);
60 #endif
61     retVal = SecInputSW(&fStr, format, argList);
62 #if SECUREC_ENABLE_SCANF_FILE
63     SECUREC_UNLOCK_STDIN(0, fStr.pf);
64 #endif
65     if (retVal < 0) {
66         SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s");
67         return SECUREC_SCANF_EINVAL;
68     }
69 
70     return retVal;
71 }
72 
73