[libc-commits] [libc] [libc] Define Annex K's errno_t in specified headers (PR #187700)

Victor Campos via libc-commits libc-commits at lists.llvm.org
Wed Mar 25 04:43:40 PDT 2026


https://github.com/vhscampos updated https://github.com/llvm/llvm-project/pull/187700

>From aa628c6a9434d9d3f5c00b44e2086919beff66f8 Mon Sep 17 00:00:00 2001
From: Victor Campos <victor.campos at arm.com>
Date: Fri, 20 Mar 2026 13:50:53 +0000
Subject: [PATCH 1/2] [libc] Define Annex K's errno_t in specified headers

 - Change `errno.h.def` to include a placeholder where hdrgen emits the
   public API, which contains the `errno_t` definition.
 - Make headers `stdio.h`, `stdlib.h`, `string.h` and `time.h` also
   define `errno_t` as specified in the standard.
---
 libc/include/CMakeLists.txt | 6 +++++-
 libc/include/errno.h.def    | 2 ++
 libc/include/stdio.yaml     | 1 +
 libc/include/stdlib.yaml    | 3 ++-
 libc/include/string.yaml    | 1 +
 libc/include/time.yaml      | 1 +
 6 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index cc0b83124d064..cc318404a5b84 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -253,6 +253,7 @@ add_header_macro(
   DEPENDS
     .llvm_libc_common_h
     .llvm-libc-macros.null_macro
+    .llvm-libc-types.errno_t
     .llvm-libc-types.size_t
 )
 
@@ -288,6 +289,7 @@ add_header_macro(
     .llvm-libc-macros.null_macro
     .llvm-libc-macros.time_macros
     .llvm-libc-types.clock_t
+    .llvm-libc-types.errno_t
     .llvm-libc-types.time_t
     .llvm-libc-types.struct_tm
     .llvm-libc-types.struct_timespec
@@ -364,8 +366,9 @@ add_header_macro(
     .llvm-libc-macros.file_seek_macros
     .llvm-libc-macros.null_macro
     .llvm-libc-macros.stdio_macros
-    .llvm-libc-types.FILE
     .llvm-libc-types.cookie_io_functions_t
+    .llvm-libc-types.errno_t
+    .llvm-libc-types.FILE
     .llvm-libc-types.off_t
     .llvm-libc-types.size_t
     .llvm-libc-types.ssize_t
@@ -384,6 +387,7 @@ add_header_macro(
     .llvm-libc-types.__qsortrcompare_t
     .llvm-libc-types.__search_compare_t
     .llvm-libc-types.div_t
+    .llvm-libc-types.errno_t
     .llvm-libc-types.ldiv_t
     .llvm-libc-types.lldiv_t
     .llvm-libc-types.locale_t
diff --git a/libc/include/errno.h.def b/libc/include/errno.h.def
index 0ac8e57f7a158..f731accc3b24b 100644
--- a/libc/include/errno.h.def
+++ b/libc/include/errno.h.def
@@ -31,6 +31,8 @@
 
 #endif
 
+%%public_api()
+
 __BEGIN_C_DECLS
 
 int *__llvm_libc_errno(void) __NOEXCEPT;
diff --git a/libc/include/stdio.yaml b/libc/include/stdio.yaml
index 67eeeaf07bdd1..ad556e659f433 100644
--- a/libc/include/stdio.yaml
+++ b/libc/include/stdio.yaml
@@ -14,6 +14,7 @@ types:
   - type_name: off_t
   - type_name: cookie_io_functions_t
   - type_name: FILE
+  - type_name: errno_t
 enums: []
 objects:
   - object_name: stdin
diff --git a/libc/include/stdlib.yaml b/libc/include/stdlib.yaml
index 4752244279243..8741b06d1bcd8 100644
--- a/libc/include/stdlib.yaml
+++ b/libc/include/stdlib.yaml
@@ -17,7 +17,8 @@ types:
   - type_name: lldiv_t
   - type_name: locale_t
   - type_name: size_t
-  - type_name: wchar_t  
+  - type_name: wchar_t
+  - type_name: errno_t
 enums: []
 objects: []
 functions:
diff --git a/libc/include/string.yaml b/libc/include/string.yaml
index 22010f4afa812..c781060bb59b6 100644
--- a/libc/include/string.yaml
+++ b/libc/include/string.yaml
@@ -5,6 +5,7 @@ macros:
   - macro_name: "NULL"
     macro_header: null-macro.h
 types:
+  - type_name: errno_t
   - type_name: locale_t
   - type_name: size_t
 enums: []
diff --git a/libc/include/time.yaml b/libc/include/time.yaml
index bf68da326ccd4..26ce829939f64 100644
--- a/libc/include/time.yaml
+++ b/libc/include/time.yaml
@@ -6,6 +6,7 @@ macros:
 types:
   - type_name: struct_timeval
   - type_name: clockid_t
+  - type_name: errno_t
   - type_name: struct_timespec
   - type_name: struct_tm
   - type_name: time_t

>From 75fbc67830b97c51d2a745668554c693e19d804c Mon Sep 17 00:00:00 2001
From: Victor Campos <victor.campos at arm.com>
Date: Wed, 25 Mar 2026 11:33:08 +0000
Subject: [PATCH 2/2] Undo unnecessary change

---
 libc/include/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index cc318404a5b84..2a252680b3d8a 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -366,9 +366,9 @@ add_header_macro(
     .llvm-libc-macros.file_seek_macros
     .llvm-libc-macros.null_macro
     .llvm-libc-macros.stdio_macros
+    .llvm-libc-types.FILE
     .llvm-libc-types.cookie_io_functions_t
     .llvm-libc-types.errno_t
-    .llvm-libc-types.FILE
     .llvm-libc-types.off_t
     .llvm-libc-types.size_t
     .llvm-libc-types.ssize_t



More information about the libc-commits mailing list