[libc-commits] [libc] [libc] Support for scanf on baremetal (PR #131043)
Petr Hosek via libc-commits
libc-commits at lists.llvm.org
Thu Mar 20 13:10:49 PDT 2025
================
@@ -0,0 +1,52 @@
+//===-- Implementation of scanf ---------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/stdio/scanf.h"
+
+#include "hdr/stdio_macros.h"
+#include "src/__support/OSUtil/io.h"
+#include "src/__support/arg_list.h"
+#include "src/__support/macros/config.h"
+#include "src/stdio/scanf_core/reader.h"
+#include "src/stdio/scanf_core/scanf_main.h"
+
+#include <stdarg.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace {
+
+struct StreamReader : scanf_core::Reader<StreamReader> {
+ LIBC_INLINE char getc() {
+ char buf[1];
+ auto result = read_from_stdin(buf, sizeof(buf));
+ if (result <= 0)
+ return EOF;
+ return buf[0];
+ }
+ LIBC_INLINE void ungetc(int) {}
+};
----------------
petrhosek wrote:
Done, I moved the implementation to `scanf_internal.h`.
https://github.com/llvm/llvm-project/pull/131043
More information about the libc-commits
mailing list