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 "securec.h"
17
18 /*******************************************************************************
19 * <FUNCTION DESCRIPTION>
20 * The scanf_s function is equivalent to fscanf_s with the argument stdin interposed before the arguments to scanf_s
21 * The scanf_s function reads data from the standard input stream stdin and
22 * writes the data into the location that's given by argument. Each argument
23 * must be a pointer to a variable of a type that corresponds to a type specifier
24 * in format. If copying occurs between strings that overlap, the behavior is
25 * undefined.
26 *
27 * <INPUT PARAMETERS>
28 * format Format control string.
29 * ... Optional arguments.
30 *
31 * <OUTPUT PARAMETERS>
32 * ... The converted value stored in user assigned address
33 *
34 * <RETURN VALUE>
35 * Returns the number of fields successfully converted and assigned;
36 * the return value does not include fields that were read but not assigned.
37 * A return value of 0 indicates that no fields were assigned.
38 * return -1 if an error occurs.
39 *******************************************************************************
40 */
41
scanf_s(const char * format,...)42 int scanf_s(const char *format, ...)
43 {
44 int ret; /* If initialization causes e838 */
45 va_list arglist;
46
47 va_start(arglist, format);
48 ret = vscanf_s(format, arglist);
49 va_end(arglist);
50 (void)arglist; /* to clear e438 last value assigned not used , the compiler will optimize this code */
51
52 return ret;
53 }
54
55
56