summaryrefslogtreecommitdiffstats
path: root/tests/xtime.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-03-07 16:18:32 -0500
committerTavian Barnes <tavianator@tavianator.com>2024-03-07 16:26:25 -0500
commit43cd776d7dc8ac573262f8459edeb1c1f5f3cd09 (patch)
tree4aae15ba3afb55506e43faf3dd36076f504fb793 /tests/xtime.c
parent416ca3b557055efa5746a4d40d927391c59a9292 (diff)
downloadbfs-43cd776d7dc8ac573262f8459edeb1c1f5f3cd09.tar.xz
xtime: Call tzset() from main() instead of lazily
POSIX specifies[1] that If a thread accesses tzname, daylight, or timezone directly while another thread is in a call to tzset(), or to any function that is required or allowed to set timezone information as if by calling tzset(), the behavior is undefined. So calling it lazily from arbitrary threads is risky. [1]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tzset.html
Diffstat (limited to 'tests/xtime.c')
-rw-r--r--tests/xtime.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/tests/xtime.c b/tests/xtime.c
index f853428..2609c1c 100644
--- a/tests/xtime.c
+++ b/tests/xtime.c
@@ -81,8 +81,8 @@ static bool check_xgetdate(void) {
/** Check one xmktime() result. */
static bool check_one_xmktime(time_t expected) {
struct tm tm;
- if (xlocaltime(&expected, &tm) != 0) {
- bfs_diag("xlocaltime(%jd): %s", (intmax_t)expected, xstrerror(errno));
+ if (!localtime_r(&expected, &tm)) {
+ bfs_diag("localtime_r(%jd): %s", (intmax_t)expected, xstrerror(errno));
return false;
}
@@ -145,12 +145,6 @@ static bool check_xtimegm(void) {
}
bool check_xtime(void) {
- if (setenv("TZ", "UTC0", true) != 0) {
- perror("setenv()");
- return false;
- }
- tzset();
-
bool ret = true;
ret &= check_xgetdate();
ret &= check_xmktime();