• 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: vfwscanf_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  vfwscanf_s  function  is  the  wide-character  equivalent  of the vfscanf_s function
25  *    The vfwscanf_s function reads data from the current position of stream into
26  *    the locations given by argument (if any). Each argument must be a pointer
27  *    to a variable of a type that corresponds to a type specifier in format.
28  *    format controls the interpretation of the input fields and has the same form
29  *    and function as the format argument for scanf.
30  *
31  * <INPUT PARAMETERS>
32  *    stream               Pointer to FILE structure.
33  *    format               Format control string, see Format Specifications.
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  *    Each of these functions returns the number of fields successfully converted
41  *    and assigned; the return value does not include fields that were read but
42  *    not assigned. A return value of 0 indicates that no fields were assigned.
43  *    return -1 if an error occurs.
44  */
vfwscanf_s(FILE * stream,const wchar_t * format,va_list argList)45 int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList)
46 {
47     int retVal; /* If initialization causes  e838 */
48     SecFileStream fStr;
49 
50     if (stream == NULL || format == NULL) {
51         SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s");
52         return SECUREC_SCANF_EINVAL;
53     }
54     if (stream == SECUREC_STREAM_STDIN) {
55         return vwscanf_s(format, argList);
56     }
57 
58     SECUREC_LOCK_FILE(stream);
59     SECUREC_FILE_STREAM_FROM_FILE(&fStr, stream);
60     retVal = SecInputSW(&fStr, format, argList);
61     SECUREC_UNLOCK_FILE(stream);
62     if (retVal < 0) {
63         SECUREC_ERROR_INVALID_PARAMTER("vfwscanf_s");
64         return SECUREC_SCANF_EINVAL;
65     }
66     return retVal;
67 }
68 
69