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