[libc-commits] [libc] [libc] Add stubs for tzset, tzname, timezone, and daylight. (PR #218979)
Alex Strelnikov via libc-commits
libc-commits at lists.llvm.org
Wed Aug 26 10:54:31 PDT 2026
https://github.com/strel-12 updated https://github.com/llvm/llvm-project/pull/218979
>From d6bd537a0ceb43bc9842f33816fbe9d8c729d619 Mon Sep 17 00:00:00 2001
From: Alex Strelnikov <strel at google.com>
Date: Wed, 26 Aug 2026 16:15:47 +0000
Subject: [PATCH 1/2] Add stubs for tzset, tzname, timezone, and daylight.
---
libc/config/linux/aarch64/entrypoints.txt | 2 ++
libc/config/linux/x86_64/entrypoints.txt | 2 ++
libc/include/time.yaml | 14 ++++++++-
libc/src/time/CMakeLists.txt | 14 +++++++++
libc/src/time/linux/CMakeLists.txt | 20 ++++++++++++
libc/src/time/linux/tz_variables.cpp | 31 +++++++++++++++++++
libc/src/time/linux/tzset.cpp | 22 +++++++++++++
libc/src/time/tz_variables.h | 28 +++++++++++++++++
libc/src/time/tzset.h | 25 +++++++++++++++
libc/test/src/time/CMakeLists.txt | 10 ++++++
libc/test/src/time/tzset_test.cpp | 17 ++++++++++
libc/utils/hdrgen/hdrgen/object.py | 5 ++-
.../tests/expected_output/test_header.h | 2 +-
libc/utils/hdrgen/tests/input/merge2.yaml | 2 +-
14 files changed, 190 insertions(+), 4 deletions(-)
create mode 100644 libc/src/time/linux/tz_variables.cpp
create mode 100644 libc/src/time/linux/tzset.cpp
create mode 100644 libc/src/time/tz_variables.h
create mode 100644 libc/src/time/tzset.h
create mode 100644 libc/test/src/time/tzset_test.cpp
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index dd20e979745c0..76003449b1e10 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1389,6 +1389,8 @@ if(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
# time.h entrypoints
libc.src.time.strptime
+ libc.src.time.tz_variables
+ libc.src.time.tzset
# wchar.h entrypoints
libc.src.wchar.swprintf
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index e78b4d47edd9f..e108d5746fadd 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1620,6 +1620,8 @@ if(LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS)
# time.h entrypoints
libc.src.time.strptime
+ libc.src.time.tz_variables
+ libc.src.time.tzset
# wchar.h entrypoints
libc.src.wchar.swprintf
diff --git a/libc/include/time.yaml b/libc/include/time.yaml
index 147bd6f5643a6..9dca1db86ca20 100644
--- a/libc/include/time.yaml
+++ b/libc/include/time.yaml
@@ -20,7 +20,13 @@ types:
- type_name: locale_t
- type_name: tm_gmtoff_t
enums: []
-objects: []
+objects:
+ - object_name: tzname
+ object_type: char *[2]
+ - object_name: timezone
+ object_type: long
+ - object_name: daylight
+ object_type: int
functions:
- name: asctime
standards:
@@ -168,4 +174,10 @@ functions:
return_type: int
arguments:
- type: timer_t
+ - name: tzset
+ standards:
+ - posix
+ return_type: void
+ arguments:
+ - type: void
diff --git a/libc/src/time/CMakeLists.txt b/libc/src/time/CMakeLists.txt
index 49ca72376090c..a9951926906f9 100644
--- a/libc/src/time/CMakeLists.txt
+++ b/libc/src/time/CMakeLists.txt
@@ -314,3 +314,17 @@ add_entrypoint_object(
.${LIBC_TARGET_OS}.timer_delete
)
+add_entrypoint_object(
+ tz_variables
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.tz_variables
+)
+
+add_entrypoint_object(
+ tzset
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.tzset
+)
+
diff --git a/libc/src/time/linux/CMakeLists.txt b/libc/src/time/linux/CMakeLists.txt
index 3f91aa3528405..963fb7c4c9530 100644
--- a/libc/src/time/linux/CMakeLists.txt
+++ b/libc/src/time/linux/CMakeLists.txt
@@ -105,3 +105,23 @@ add_entrypoint_object(
libc.src.errno.errno
)
+add_entrypoint_object(
+ tz_variables
+ SRCS
+ tz_variables.cpp
+ HDRS
+ ../tz_variables.h
+ DEPENDS
+ libc.src.__support.macros.config
+)
+
+add_entrypoint_object(
+ tzset
+ SRCS
+ tzset.cpp
+ HDRS
+ ../tzset.h
+ DEPENDS
+ libc.src.__support.macros.config
+)
+
diff --git a/libc/src/time/linux/tz_variables.cpp b/libc/src/time/linux/tz_variables.cpp
new file mode 100644
index 0000000000000..c36182cb48965
--- /dev/null
+++ b/libc/src/time/linux/tz_variables.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// This file contains the definitions of the tzname, timezone, and daylight
+/// variables.
+///
+//===----------------------------------------------------------------------===//
+
+#ifdef LIBC_FULL_BUILD
+
+#include "src/time/tz_variables.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+using TZNameArrayType = char *[2];
+
+LLVM_LIBC_VARIABLE(TZNameArrayType, tzname) = {};
+LLVM_LIBC_VARIABLE(long, timezone) = 0;
+LLVM_LIBC_VARIABLE(int, daylight) = 0;
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_FULL_BUILD
diff --git a/libc/src/time/linux/tzset.cpp b/libc/src/time/linux/tzset.cpp
new file mode 100644
index 0000000000000..5cf43c3a7947a
--- /dev/null
+++ b/libc/src/time/linux/tzset.cpp
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// This file contains the definition of the tzset function.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/time/tzset.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(void, tzset, ()) {}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/time/tz_variables.h b/libc/src/time/tz_variables.h
new file mode 100644
index 0000000000000..7dc4143747d59
--- /dev/null
+++ b/libc/src/time/tz_variables.h
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// This file contains the declarations of the tzname, timezone, and daylight
+/// variables.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_TIME_TZNAME_H
+#define LLVM_LIBC_SRC_TIME_TZNAME_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+extern char *tzname[2];
+extern long timezone;
+extern int daylight;
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_TIME_TZNAME_H
diff --git a/libc/src/time/tzset.h b/libc/src/time/tzset.h
new file mode 100644
index 0000000000000..81d4d5df4e7df
--- /dev/null
+++ b/libc/src/time/tzset.h
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// This file contains the declaration of the strptime function.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_TIME_TZSET_H
+#define LLVM_LIBC_SRC_TIME_TZSET_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+void tzset();
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_TIME_TZSET_H
diff --git a/libc/test/src/time/CMakeLists.txt b/libc/test/src/time/CMakeLists.txt
index cf4c18e8d9d37..7bab0a2e40288 100644
--- a/libc/test/src/time/CMakeLists.txt
+++ b/libc/test/src/time/CMakeLists.txt
@@ -293,3 +293,13 @@ add_libc_test(
libc.src.errno.errno
libc.hdr.types.clock_t
)
+
+add_libc_test(
+ tzset_test
+ SUITE
+ libc_time_unittests
+ SRCS
+ tzset_test.cpp
+ DEPENDS
+ libc.src.time.tzset
+)
diff --git a/libc/test/src/time/tzset_test.cpp b/libc/test/src/time/tzset_test.cpp
new file mode 100644
index 0000000000000..4659cf903bfe3
--- /dev/null
+++ b/libc/test/src/time/tzset_test.cpp
@@ -0,0 +1,17 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+/// Unit test for tzset.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/time/tzset.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcTzsetTest, StubCallable) { LIBC_NAMESPACE::tzset(); }
diff --git a/libc/utils/hdrgen/hdrgen/object.py b/libc/utils/hdrgen/hdrgen/object.py
index a2ab496bed013..deaeadd01ac1b 100644
--- a/libc/utils/hdrgen/hdrgen/object.py
+++ b/libc/utils/hdrgen/hdrgen/object.py
@@ -15,4 +15,7 @@ def __init__(self, name, type):
self.type = type
def __str__(self):
- return f"extern {self.type} {self.name};"
+ split_type = self.type.partition("[")
+ scalar_type = split_type[0]
+ array_size = split_type[1] + split_type[2]
+ return f"extern {scalar_type} {self.name}{array_size};"
diff --git a/libc/utils/hdrgen/tests/expected_output/test_header.h b/libc/utils/hdrgen/tests/expected_output/test_header.h
index b35de7b2f337a..b866fb741d83f 100644
--- a/libc/utils/hdrgen/tests/expected_output/test_header.h
+++ b/libc/utils/hdrgen/tests/expected_output/test_header.h
@@ -50,7 +50,7 @@ _Float16 func_e(float128) __NOEXCEPT;
#endif // LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128
extern obj object_1;
-extern obj object_2;
+extern obj object_2[3];
__END_C_DECLS
diff --git a/libc/utils/hdrgen/tests/input/merge2.yaml b/libc/utils/hdrgen/tests/input/merge2.yaml
index a653b74455320..76d20d50c1003 100644
--- a/libc/utils/hdrgen/tests/input/merge2.yaml
+++ b/libc/utils/hdrgen/tests/input/merge2.yaml
@@ -8,7 +8,7 @@ enums:
value: value_2
objects:
- object_name: object_2
- object_type: obj
+ object_type: obj[3]
functions:
- name: func_b
return_type: float128
>From 62c0de3ac2cf28c3cfa1c739a63858464fddb06a Mon Sep 17 00:00:00 2001
From: Alex Strelnikov <strel at google.com>
Date: Wed, 26 Aug 2026 16:21:33 +0000
Subject: [PATCH 2/2] copy/paste fix
---
libc/src/time/tzset.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/time/tzset.h b/libc/src/time/tzset.h
index 81d4d5df4e7df..cafb9a227cd53 100644
--- a/libc/src/time/tzset.h
+++ b/libc/src/time/tzset.h
@@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
///
/// \file
-/// This file contains the declaration of the strptime function.
+/// This file contains the declaration of the tzset function.
///
//===----------------------------------------------------------------------===//
More information about the libc-commits
mailing list