1 | //===-- Implementation of scanf ---------------------------------*- C++ -*-===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "src/stdio/scanf.h" |
10 | |
11 | #include "hdr/stdio_macros.h" |
12 | #include "src/__support/OSUtil/io.h" |
13 | #include "src/__support/arg_list.h" |
14 | #include "src/__support/macros/config.h" |
15 | #include "src/stdio/baremetal/scanf_internal.h" |
16 | #include "src/stdio/scanf_core/scanf_main.h" |
17 | |
18 | #include <stdarg.h> |
19 | |
20 | namespace LIBC_NAMESPACE_DECL { |
21 | |
22 | LLVM_LIBC_FUNCTION(int, scanf, (const char *__restrict format, ...)) { |
23 | va_list vlist; |
24 | va_start(vlist, format); |
25 | internal::ArgList args(vlist); // This holder class allows for easier copying |
26 | // and pointer semantics, as well as handling |
27 | // destruction automatically. |
28 | va_end(vlist); |
29 | |
30 | scanf_core::StdinReader reader; |
31 | int retval = scanf_core::scanf_main(&reader, format, args); |
32 | // This is done to avoid including stdio.h in the internals. On most systems |
33 | // EOF is -1, so this will be transformed into just "return retval". |
34 | return (retval == -1) ? EOF : retval; |
35 | } |
36 | |
37 | } // namespace LIBC_NAMESPACE_DECL |
38 |