[libc-commits] [libc] [libc] Include EOF macro in stdio.h on baremetal (PR #85159)

Petr Hosek via libc-commits libc-commits at lists.llvm.org
Wed Mar 13 23:21:08 PDT 2024


https://github.com/petrhosek updated https://github.com/llvm/llvm-project/pull/85159

>From 5ab1ef66ecb97453b2767d09a65ebf6bacf0ad55 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Wed, 13 Mar 2024 00:28:47 -0700
Subject: [PATCH 1/2] [libc] Include EOF macro in stdio.h on baremetal

libc++ char_traits.h assumes EOF is always available

See #85158 for more details.
---
 libc/config/baremetal/api.td | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/libc/config/baremetal/api.td b/libc/config/baremetal/api.td
index 80d0e0ba22ca51..e33c1ff5521902 100644
--- a/libc/config/baremetal/api.td
+++ b/libc/config/baremetal/api.td
@@ -52,6 +52,15 @@ def IntTypesAPI : PublicAPI<"inttypes.h"> {
   let Types = ["imaxdiv_t"];
 }
 
+def StdIOAPI : PublicAPI<"stdio.h"> {
+  let Macros = [
+    SimpleMacroDef<"EOF", "-1">,
+  ];
+  let Types = [
+    "size_t"
+  ];
+}
+
 def StdlibAPI : PublicAPI<"stdlib.h"> {
   let Types = [
     "div_t",

>From 6e546690a04a9fdec198a56dba2216003319f1d6 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Wed, 13 Mar 2024 23:19:53 -0700
Subject: [PATCH 2/2] Move the definition to
 libc/include/llvm-libc-macros/stdio-macros.h

---
 libc/config/baremetal/api.td                 | 7 +------
 libc/include/llvm-libc-macros/stdio-macros.h | 4 ++++
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/libc/config/baremetal/api.td b/libc/config/baremetal/api.td
index e33c1ff5521902..9548cc47203d7d 100644
--- a/libc/config/baremetal/api.td
+++ b/libc/config/baremetal/api.td
@@ -53,12 +53,7 @@ def IntTypesAPI : PublicAPI<"inttypes.h"> {
 }
 
 def StdIOAPI : PublicAPI<"stdio.h"> {
-  let Macros = [
-    SimpleMacroDef<"EOF", "-1">,
-  ];
-  let Types = [
-    "size_t"
-  ];
+  let Types = ["size_t"];
 }
 
 def StdlibAPI : PublicAPI<"stdlib.h"> {
diff --git a/libc/include/llvm-libc-macros/stdio-macros.h b/libc/include/llvm-libc-macros/stdio-macros.h
index db747c5d5d6755..8c1b0b6b7a0b38 100644
--- a/libc/include/llvm-libc-macros/stdio-macros.h
+++ b/libc/include/llvm-libc-macros/stdio-macros.h
@@ -9,6 +9,10 @@
 #ifndef LLVM_LIBC_MACROS_STDIO_MACROS_H
 #define LLVM_LIBC_MACROS_STDIO_MACROS_H
 
+#ifndef EOF
+#define EOF -1
+#endif
+
 #define BUFSIZ 1024
 
 #endif // LLVM_LIBC_MACROS_STDIO_MACROS_H



More information about the libc-commits mailing list