[libc-commits] [libc] [libc] Add file constants (PR #230230)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Thu Oct 8 11:02:10 PDT 2026


https://github.com/michaelrj-google created https://github.com/llvm/llvm-project/pull/230230

POSIX defines FILENAME_MAX and FOPEN_MAX, this PR adds values for them.

See: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html


>From 8acee0edaa11c30c9e66bd37fc0b5212b2f5eb3b Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Thu, 8 Oct 2026 18:01:12 +0000
Subject: [PATCH] [libc] Add file constants

POSIX defines FILENAME_MAX and FOPEN_MAX, this PR adds values for them.

See: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/stdio.h.html
---
 libc/include/llvm-libc-macros/stdio-macros.h | 11 +++++++++++
 libc/include/stdio.yaml                      |  4 ++++
 2 files changed, 15 insertions(+)

diff --git a/libc/include/llvm-libc-macros/stdio-macros.h b/libc/include/llvm-libc-macros/stdio-macros.h
index 192c161b8ec8d9..e419a6aed5bc51 100644
--- a/libc/include/llvm-libc-macros/stdio-macros.h
+++ b/libc/include/llvm-libc-macros/stdio-macros.h
@@ -73,4 +73,15 @@ extern FILE *stderr;
 #define TMP_MAX 1000000
 #endif
 
+// match linux/limits.h PATH_MAX
+#ifndef FILENAME_MAX
+#define FILENAME_MAX 4096
+#endif
+
+// Actually a lower bound on how many files we guarantee can be open at once.
+// POSIX says "at least eight", which seems like a fine number to me.
+#ifndef FOPEN_MAX
+#define FOPEN_MAX 8
+#endif
+
 #endif // LLVM_LIBC_MACROS_STDIO_MACROS_H
diff --git a/libc/include/stdio.yaml b/libc/include/stdio.yaml
index 1b3aaa2ccea162..1ac0422866fb8c 100644
--- a/libc/include/stdio.yaml
+++ b/libc/include/stdio.yaml
@@ -30,6 +30,10 @@ macros:
     macro_header: stdio-macros.h
   - macro_name: TMP_MAX
     macro_header: stdio-macros.h
+  - macro_name: FILENAME_MAX
+    macro_header: stdio-macros.h
+  - macro_name: FOPEN_MAX
+    macro_header: stdio-macros.h
 types:
   - type_name: rsize_t
   - type_name: size_t



More information about the libc-commits mailing list