1 //===-- Implementation of vsscanf -------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "src/stdio/vsscanf.h"
11 #include "hdr/stdio_macros.h"
12 #include "src/__support/CPP/limits.h"
13 #include "src/__support/arg_list.h"
14 #include "src/stdio/scanf_core/reader.h"
15 #include "src/stdio/scanf_core/scanf_main.h"
19 namespace LIBC_NAMESPACE_DECL
{
21 LLVM_LIBC_FUNCTION(int, vsscanf
,
22 (const char *buffer
, const char *format
, va_list vlist
)) {
23 internal::ArgList
args(vlist
);
24 scanf_core::ReadBuffer rb
{const_cast<char *>(buffer
),
25 cpp::numeric_limits
<size_t>::max()};
26 scanf_core::Reader
reader(&rb
);
27 int ret_val
= scanf_core::scanf_main(&reader
, format
, args
);
28 // This is done to avoid including stdio.h in the internals. On most systems
29 // EOF is -1, so this will be transformed into just "return ret_val".
30 return (ret_val
== -1) ? EOF
: ret_val
;
33 } // namespace LIBC_NAMESPACE_DECL