• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2014-2020. 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  * Author: lishunda
13  * Create: 2014-02-25
14  */
15 
16 #ifndef SECUREC_FOR_WCHAR
17 #define SECUREC_FOR_WCHAR
18 #endif
19 
20 #include "secinput.h"
21 
22 /*
23  * <FUNCTION DESCRIPTION>
24  *    The  vwscanf_s  function  is  the  wide-character  equivalent  of the vscanf_s function
25  *    The vwscanf_s function is the wide-character version of vscanf_s. The
26  *    function reads data from the standard input stream stdin and writes the
27  *    data into the location that's given by argument. Each argument  must be a
28  *    pointer to a variable of a type that corresponds to a type specifier in
29  *    format. If copying occurs between strings that overlap, the behavior is
30  *    undefined.
31  *
32  * <INPUT PARAMETERS>
33  *    format                 Format control string.
34  *    argList                pointer to list of arguments
35  *
36  * <OUTPUT PARAMETERS>
37  *    argList                the converted value stored in user assigned address
38  *
39  * <RETURN VALUE>
40  *    Returns the number of fields successfully converted and assigned;
41  *    the return value does not include fields that were read but not assigned.
42  *    A return value of 0 indicates that no fields were assigned.
43  *    return -1 if an error occurs.
44  */
vwscanf_s(const wchar_t * format,va_list argList)45 int vwscanf_s(const wchar_t *format, va_list argList)
46 {
47     int retVal;                 /* If initialization causes  e838 */
48     SecFileStream fStr;
49     SECUREC_FILE_STREAM_FROM_STDIN(&fStr);
50     if (format == NULL || fStr.pf == NULL) {
51         SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s");
52         return SECUREC_SCANF_EINVAL;
53     }
54 
55     SECUREC_LOCK_STDIN(0, fStr.pf);
56     retVal = SecInputSW(&fStr, format, argList);
57     SECUREC_UNLOCK_STDIN(0, fStr.pf);
58     if (retVal < 0) {
59         SECUREC_ERROR_INVALID_PARAMTER("vwscanf_s");
60         return SECUREC_SCANF_EINVAL;
61     }
62 
63     return retVal;
64 }
65 
66