[libc-commits] [libc] [libc] Add langinfo.h header generation, macros, and types (PR #210941)
Jeff Bailey via libc-commits
libc-commits at lists.llvm.org
Wed Jul 22 03:39:34 PDT 2026
https://github.com/kaladron updated https://github.com/llvm/llvm-project/pull/210941
>From 14eca1360032d90c35d00d36538f225269061c40 Mon Sep 17 00:00:00 2001
From: Jeff Bailey <jbailey at raspberryginger.com>
Date: Mon, 20 Jul 2026 23:58:22 +0100
Subject: [PATCH] [libc] Add langinfo.h header generation, macros, and types
Add header generation support for langinfo.h, including nl_item type
definition, langinfo macros, and YAML header specification.
* libc/include/llvm-libc-types/nl_item.h: Define nl_item type
* libc/include/llvm-libc-macros/langinfo-macros.h: Define POSIX macros
* libc/include/langinfo.yaml: Define langinfo.h interface
* libc/include/langinfo.h.def: Header template
* libc/config/linux/*/headers.txt: Enable langinfo header for Linux
Assisted-by: Automated tooling, human reviewed.
---
libc/config/linux/aarch64/headers.txt | 1 +
libc/config/linux/arm/headers.txt | 1 +
libc/config/linux/i386/headers.txt | 1 +
libc/config/linux/riscv/headers.txt | 1 +
libc/config/linux/x86_64/headers.txt | 1 +
libc/include/CMakeLists.txt | 11 ++
libc/include/langinfo.yaml | 131 ++++++++++++++++++
libc/include/llvm-libc-macros/CMakeLists.txt | 8 ++
.../llvm-libc-macros/langinfo-macros.h | 86 ++++++++++++
libc/include/llvm-libc-types/CMakeLists.txt | 1 +
libc/include/llvm-libc-types/nl_item.h | 19 +++
11 files changed, 261 insertions(+)
create mode 100644 libc/include/langinfo.yaml
create mode 100644 libc/include/llvm-libc-macros/langinfo-macros.h
create mode 100644 libc/include/llvm-libc-types/nl_item.h
diff --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index 2cb33a2f75416..a0dae81f46e6e 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -16,6 +16,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.fenv
libc.include.float
libc.include.inttypes
+ libc.include.langinfo
libc.include.libgen
libc.include.limits
libc.include.link
diff --git a/libc/config/linux/arm/headers.txt b/libc/config/linux/arm/headers.txt
index 43f233637c35e..cc0a509d6921a 100644
--- a/libc/config/linux/arm/headers.txt
+++ b/libc/config/linux/arm/headers.txt
@@ -7,6 +7,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.fenv
libc.include.float
libc.include.inttypes
+ libc.include.langinfo
libc.include.libgen
libc.include.malloc
libc.include.math
diff --git a/libc/config/linux/i386/headers.txt b/libc/config/linux/i386/headers.txt
index cce115d5f59df..def05189f136d 100644
--- a/libc/config/linux/i386/headers.txt
+++ b/libc/config/linux/i386/headers.txt
@@ -2,4 +2,5 @@ set(TARGET_PUBLIC_HEADERS
libc.include.alloca
libc.include.assert
libc.include.cpio
+ libc.include.langinfo
)
diff --git a/libc/config/linux/riscv/headers.txt b/libc/config/linux/riscv/headers.txt
index 29ae0d8b4ecfa..81af60dbf429d 100644
--- a/libc/config/linux/riscv/headers.txt
+++ b/libc/config/linux/riscv/headers.txt
@@ -16,6 +16,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.fenv
libc.include.float
libc.include.inttypes
+ libc.include.langinfo
libc.include.libgen
libc.include.limits
libc.include.link
diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index 9786b60fa2022..8e19e2a4b5a33 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -16,6 +16,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.fenv
libc.include.float
libc.include.inttypes
+ libc.include.langinfo
libc.include.libgen
libc.include.limits
libc.include.link
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index a87a2c5e39ad4..e3cbbd059774a 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -1069,6 +1069,17 @@ add_header_macro(
.llvm-libc-types.nl_catd
)
+add_header_macro(
+ langinfo
+ ../libc/include/langinfo.yaml
+ langinfo.h
+ DEPENDS
+ .llvm_libc_common_h
+ .llvm-libc-macros.langinfo_macros
+ .llvm-libc-types.nl_item
+ .llvm-libc-types.locale_t
+ )
+
# UEFI spec references "Uefi.h" so we use that name for compatibility
add_header_macro(
uefi
diff --git a/libc/include/langinfo.yaml b/libc/include/langinfo.yaml
new file mode 100644
index 0000000000000..4afd89e01ed7e
--- /dev/null
+++ b/libc/include/langinfo.yaml
@@ -0,0 +1,131 @@
+header: langinfo.h
+standards:
+ - posix
+macros:
+ - macro_name: CODESET
+ macro_header: langinfo-macros.h
+ - macro_name: D_T_FMT
+ macro_header: langinfo-macros.h
+ - macro_name: D_FMT
+ macro_header: langinfo-macros.h
+ - macro_name: T_FMT
+ macro_header: langinfo-macros.h
+ - macro_name: T_FMT_AMPM
+ macro_header: langinfo-macros.h
+ - macro_name: AM_STR
+ macro_header: langinfo-macros.h
+ - macro_name: PM_STR
+ macro_header: langinfo-macros.h
+ - macro_name: DAY_1
+ macro_header: langinfo-macros.h
+ - macro_name: DAY_2
+ macro_header: langinfo-macros.h
+ - macro_name: DAY_3
+ macro_header: langinfo-macros.h
+ - macro_name: DAY_4
+ macro_header: langinfo-macros.h
+ - macro_name: DAY_5
+ macro_header: langinfo-macros.h
+ - macro_name: DAY_6
+ macro_header: langinfo-macros.h
+ - macro_name: DAY_7
+ macro_header: langinfo-macros.h
+ - macro_name: ABDAY_1
+ macro_header: langinfo-macros.h
+ - macro_name: ABDAY_2
+ macro_header: langinfo-macros.h
+ - macro_name: ABDAY_3
+ macro_header: langinfo-macros.h
+ - macro_name: ABDAY_4
+ macro_header: langinfo-macros.h
+ - macro_name: ABDAY_5
+ macro_header: langinfo-macros.h
+ - macro_name: ABDAY_6
+ macro_header: langinfo-macros.h
+ - macro_name: ABDAY_7
+ macro_header: langinfo-macros.h
+ - macro_name: MON_1
+ macro_header: langinfo-macros.h
+ - macro_name: MON_2
+ macro_header: langinfo-macros.h
+ - macro_name: MON_3
+ macro_header: langinfo-macros.h
+ - macro_name: MON_4
+ macro_header: langinfo-macros.h
+ - macro_name: MON_5
+ macro_header: langinfo-macros.h
+ - macro_name: MON_6
+ macro_header: langinfo-macros.h
+ - macro_name: MON_7
+ macro_header: langinfo-macros.h
+ - macro_name: MON_8
+ macro_header: langinfo-macros.h
+ - macro_name: MON_9
+ macro_header: langinfo-macros.h
+ - macro_name: MON_10
+ macro_header: langinfo-macros.h
+ - macro_name: MON_11
+ macro_header: langinfo-macros.h
+ - macro_name: MON_12
+ macro_header: langinfo-macros.h
+ - macro_name: ABMON_1
+ macro_header: langinfo-macros.h
+ - macro_name: ABMON_2
+ macro_header: langinfo-macros.h
+ - macro_name: ABMON_3
+ macro_header: langinfo-macros.h
+ - macro_name: ABMON_4
+ macro_header: langinfo-macros.h
+ - macro_name: ABMON_5
+ macro_header: langinfo-macros.h
+ - macro_name: ABMON_6
+ macro_header: langinfo-macros.h
+ - macro_name: ABMON_7
+ macro_header: langinfo-macros.h
+ - macro_name: ABMON_8
+ macro_header: langinfo-macros.h
+ - macro_name: ABMON_9
+ macro_header: langinfo-macros.h
+ - macro_name: ABMON_10
+ macro_header: langinfo-macros.h
+ - macro_name: ABMON_11
+ macro_header: langinfo-macros.h
+ - macro_name: ABMON_12
+ macro_header: langinfo-macros.h
+ - macro_name: ERA
+ macro_header: langinfo-macros.h
+ - macro_name: ERA_D_FMT
+ macro_header: langinfo-macros.h
+ - macro_name: ERA_D_T_FMT
+ macro_header: langinfo-macros.h
+ - macro_name: ERA_T_FMT
+ macro_header: langinfo-macros.h
+ - macro_name: ALT_DIGITS
+ macro_header: langinfo-macros.h
+ - macro_name: RADIXCHAR
+ macro_header: langinfo-macros.h
+ - macro_name: THOUSEP
+ macro_header: langinfo-macros.h
+ - macro_name: YESEXPR
+ macro_header: langinfo-macros.h
+ - macro_name: NOEXPR
+ macro_header: langinfo-macros.h
+ - macro_name: CRNCYSTR
+ macro_header: langinfo-macros.h
+types:
+ - type_name: nl_item
+ - type_name: locale_t
+functions:
+ - name: nl_langinfo
+ standards:
+ - posix
+ return_type: char *
+ arguments:
+ - type: nl_item
+ - name: nl_langinfo_l
+ standards:
+ - posix
+ return_type: char *
+ arguments:
+ - type: nl_item
+ - type: locale_t
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index 8babf3c69ebf6..3e7bdd1bed7a6 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -406,6 +406,14 @@ add_macro_header(
locale-macros.h
)
+add_macro_header(
+ langinfo_macros
+ HDR
+ langinfo-macros.h
+ DEPENDS
+ .locale_macros
+)
+
add_macro_header(
nl_types_macros
HDR
diff --git a/libc/include/llvm-libc-macros/langinfo-macros.h b/libc/include/llvm-libc-macros/langinfo-macros.h
new file mode 100644
index 0000000000000..11048de6f488e
--- /dev/null
+++ b/libc/include/llvm-libc-macros/langinfo-macros.h
@@ -0,0 +1,86 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of macros from langinfo.h.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_MACROS_LANGINFO_MACROS_H
+#define LLVM_LIBC_MACROS_LANGINFO_MACROS_H
+
+#include "locale-macros.h"
+
+#define _NL_ITEM(category, index) (((category) << 16) | (index))
+
+#define CODESET _NL_ITEM(LC_CTYPE, 0)
+
+#define RADIXCHAR _NL_ITEM(LC_NUMERIC, 0)
+#define THOUSEP _NL_ITEM(LC_NUMERIC, 1)
+
+#define D_T_FMT _NL_ITEM(LC_TIME, 0)
+#define D_FMT _NL_ITEM(LC_TIME, 1)
+#define T_FMT _NL_ITEM(LC_TIME, 2)
+#define T_FMT_AMPM _NL_ITEM(LC_TIME, 3)
+#define AM_STR _NL_ITEM(LC_TIME, 4)
+#define PM_STR _NL_ITEM(LC_TIME, 5)
+
+#define DAY_1 _NL_ITEM(LC_TIME, 6)
+#define DAY_2 _NL_ITEM(LC_TIME, 7)
+#define DAY_3 _NL_ITEM(LC_TIME, 8)
+#define DAY_4 _NL_ITEM(LC_TIME, 9)
+#define DAY_5 _NL_ITEM(LC_TIME, 10)
+#define DAY_6 _NL_ITEM(LC_TIME, 11)
+#define DAY_7 _NL_ITEM(LC_TIME, 12)
+
+#define ABDAY_1 _NL_ITEM(LC_TIME, 13)
+#define ABDAY_2 _NL_ITEM(LC_TIME, 14)
+#define ABDAY_3 _NL_ITEM(LC_TIME, 15)
+#define ABDAY_4 _NL_ITEM(LC_TIME, 16)
+#define ABDAY_5 _NL_ITEM(LC_TIME, 17)
+#define ABDAY_6 _NL_ITEM(LC_TIME, 18)
+#define ABDAY_7 _NL_ITEM(LC_TIME, 19)
+
+#define MON_1 _NL_ITEM(LC_TIME, 20)
+#define MON_2 _NL_ITEM(LC_TIME, 21)
+#define MON_3 _NL_ITEM(LC_TIME, 22)
+#define MON_4 _NL_ITEM(LC_TIME, 23)
+#define MON_5 _NL_ITEM(LC_TIME, 24)
+#define MON_6 _NL_ITEM(LC_TIME, 25)
+#define MON_7 _NL_ITEM(LC_TIME, 26)
+#define MON_8 _NL_ITEM(LC_TIME, 27)
+#define MON_9 _NL_ITEM(LC_TIME, 28)
+#define MON_10 _NL_ITEM(LC_TIME, 29)
+#define MON_11 _NL_ITEM(LC_TIME, 30)
+#define MON_12 _NL_ITEM(LC_TIME, 31)
+
+#define ABMON_1 _NL_ITEM(LC_TIME, 32)
+#define ABMON_2 _NL_ITEM(LC_TIME, 33)
+#define ABMON_3 _NL_ITEM(LC_TIME, 34)
+#define ABMON_4 _NL_ITEM(LC_TIME, 35)
+#define ABMON_5 _NL_ITEM(LC_TIME, 36)
+#define ABMON_6 _NL_ITEM(LC_TIME, 37)
+#define ABMON_7 _NL_ITEM(LC_TIME, 38)
+#define ABMON_8 _NL_ITEM(LC_TIME, 39)
+#define ABMON_9 _NL_ITEM(LC_TIME, 40)
+#define ABMON_10 _NL_ITEM(LC_TIME, 41)
+#define ABMON_11 _NL_ITEM(LC_TIME, 42)
+#define ABMON_12 _NL_ITEM(LC_TIME, 43)
+
+#define ERA _NL_ITEM(LC_TIME, 44)
+#define ERA_D_FMT _NL_ITEM(LC_TIME, 45)
+#define ERA_D_T_FMT _NL_ITEM(LC_TIME, 46)
+#define ERA_T_FMT _NL_ITEM(LC_TIME, 47)
+#define ALT_DIGITS _NL_ITEM(LC_TIME, 48)
+
+#define CRNCYSTR _NL_ITEM(LC_MONETARY, 0)
+
+#define YESEXPR _NL_ITEM(LC_MESSAGES, 0)
+#define NOEXPR _NL_ITEM(LC_MESSAGES, 1)
+
+#endif // LLVM_LIBC_MACROS_LANGINFO_MACROS_H
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 5ea8ca0634834..070ee0c585694 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -81,6 +81,7 @@ add_header(mode_t HDR mode_t.h)
add_header(mtx_t HDR mtx_t.h DEPENDS .__futex_word .__mutex_type)
add_header(nfds_t HDR nfds_t.h)
add_header(nl_catd HDR nl_catd.h)
+add_header(nl_item HDR nl_item.h)
add_header(nlink_t HDR nlink_t.h)
add_header(off_t HDR off_t.h)
add_header(once_flag HDR once_flag.h DEPENDS .__futex_word)
diff --git a/libc/include/llvm-libc-types/nl_item.h b/libc/include/llvm-libc-types/nl_item.h
new file mode 100644
index 0000000000000..4b3a32ccd2d05
--- /dev/null
+++ b/libc/include/llvm-libc-types/nl_item.h
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of nl_item type.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_NL_ITEM_H
+#define LLVM_LIBC_TYPES_NL_ITEM_H
+
+typedef int nl_item;
+
+#endif // LLVM_LIBC_TYPES_NL_ITEM_H
More information about the libc-commits
mailing list