[libc-commits] [libc] [libc] Add putc, fputc, and fprintf to stdio/baremetal (PR #144567)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Tue Jun 17 10:18:10 PDT 2025
================
@@ -0,0 +1,25 @@
+//===-- Baremetal Implementation of putc ----------------------------------===//
+//
+// 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/putc.h"
+
+#include "src/__support/CPP/string_view.h"
+#include "src/__support/macros/config.h"
+#include "src/stdio/baremetal/write_utils.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, putc, (int c, ::FILE *stream)) {
+ char uc = static_cast<char>(c);
+
+ write(stream, cpp::string_view(&uc, 1));
----------------
michaelrj-google wrote:
calling a function without an explicit namespace that shares a name with a public libc function can be dangerous. I'd recommend renaming this function or putting it in an explicit namespace.
https://github.com/llvm/llvm-project/pull/144567
More information about the libc-commits
mailing list