[libc-commits] [libc] [libc] Add getc, ungetc, fflush to enable libc++ iostream on baremetal (PR #175530)

via libc-commits libc-commits at lists.llvm.org
Tue Jan 13 08:50:50 PST 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- libc/src/stdio/baremetal/fflush.cpp libc/src/stdio/baremetal/file_internal.cpp libc/src/stdio/baremetal/ungetc.cpp libc/src/stdio/baremetal/file_internal.h libc/src/stdio/baremetal/getc.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libc/src/stdio/baremetal/fflush.cpp b/libc/src/stdio/baremetal/fflush.cpp
index 14c124da2..4a39c25ae 100644
--- a/libc/src/stdio/baremetal/fflush.cpp
+++ b/libc/src/stdio/baremetal/fflush.cpp
@@ -13,10 +13,10 @@
 namespace LIBC_NAMESPACE_DECL {
 
 // Baremetal uses unbuffered I/O, so there is nothing to flush.
-LLVM_LIBC_FUNCTION(int, fflush, (::FILE * stream )) {
-    (void) stream;
-    // TODO: Shall we have an embedding API for fflush?
-    return 0;
+LLVM_LIBC_FUNCTION(int, fflush, (::FILE * stream)) {
+  (void)stream;
+  // TODO: Shall we have an embedding API for fflush?
+  return 0;
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/baremetal/file_internal.cpp b/libc/src/stdio/baremetal/file_internal.cpp
index cee38b2a1..52f3ba74a 100644
--- a/libc/src/stdio/baremetal/file_internal.cpp
+++ b/libc/src/stdio/baremetal/file_internal.cpp
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "src/__support/CPP/optional.h"
 #include "src/stdio/baremetal/file_internal.h"
+#include "src/__support/CPP/optional.h"
 
 #include "hdr/stdio_macros.h" // for EOF
 
@@ -45,7 +45,8 @@ int store_ungetc_value(::FILE *stream, int c) {
   if (ungetc_state_stdin)
     return EOF;
 
-  ungetc_state_stdin = cpp::optional<unsigned char>{static_cast<unsigned char>(c)};
+  ungetc_state_stdin =
+      cpp::optional<unsigned char>{static_cast<unsigned char>(c)};
   return c;
 }
 
diff --git a/libc/src/stdio/baremetal/file_internal.h b/libc/src/stdio/baremetal/file_internal.h
index e6b0d0848..8a6fc4e99 100644
--- a/libc/src/stdio/baremetal/file_internal.h
+++ b/libc/src/stdio/baremetal/file_internal.h
@@ -46,7 +46,7 @@ LIBC_INLINE FileIOResult read_internal(char *buf, size_t size, ::FILE *stream) {
   if (pop_ungetc_value(stream, ungetc_value)) {
     buf[0] = static_cast<char>(ungetc_value);
     ungetc_value_copied = 1;
-    
+
     if (size == 1)
       return 1;
   }

``````````

</details>


https://github.com/llvm/llvm-project/pull/175530


More information about the libc-commits mailing list