• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 vfscanf_s function is equivalent to fscanf_s, with the variable argument list replaced by arglist
21  *    The vfscanf_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
25  *    form and function as the format argument for scanf.
26  *
27  * <INPUT PARAMETERS>
28  *    stream               Pointer to FILE structure.
29  *    format               Format control string, see Format Specifications.
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  *    Each of these functions returns the number of fields successfully converted
37  *    and assigned; the return value does not include fields that were read but
38  *    not assigned. A return value of 0 indicates that no fields were assigned.
39  *    return -1 if an error occurs.
40  *******************************************************************************
41  */
vfscanf_s(FILE * stream,const char * format,va_list arglist)42 int vfscanf_s(FILE *stream, const char *format, va_list arglist)
43 {
44     int retVal;                 /* If initialization causes  e838 */
45     SecFileStream fStr = SECUREC_INIT_SEC_FILE_STREAM;
46 
47     if ((stream == NULL) || (format == NULL)) {
48         SECUREC_ERROR_INVALID_PARAMTER("vfscanf_s");
49         return SECUREC_SCANF_EINVAL;
50     }
51     if (stream == stdin) {
52         return vscanf_s(format, arglist);
53     }
54 
55     SECUREC_LOCK_FILE(stream);
56     fStr.pf = stream;
57     fStr.flag = SECUREC_FILE_STREAM_FLAG;
58     fStr.oriFilePos = SECUREC_UNINITIALIZED_FILE_POS;
59 
60     retVal = SecInputS(&fStr, format, arglist);
61 
62     SECUREC_UNLOCK_FILE(stream);
63     if (retVal < 0) {
64         SECUREC_ERROR_INVALID_PARAMTER("vfscanf_s");
65         return SECUREC_SCANF_EINVAL;
66     }
67 
68     return retVal;
69 }
70 
71 
72