diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-03-07 16:18:32 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-03-07 16:26:25 -0500 |
commit | 43cd776d7dc8ac573262f8459edeb1c1f5f3cd09 (patch) | |
tree | 4aae15ba3afb55506e43faf3dd36076f504fb793 /src/printf.c | |
parent | 416ca3b557055efa5746a4d40d927391c59a9292 (diff) | |
download | bfs-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 'src/printf.c')
-rw-r--r-- | src/printf.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/printf.c b/src/printf.c index 1fe8cc3..34ed606 100644 --- a/src/printf.c +++ b/src/printf.c @@ -123,7 +123,7 @@ static int bfs_printf_ctime(CFILE *cfile, const struct bfs_fmt *fmt, const struc } struct tm tm; - if (xlocaltime(&ts->tv_sec, &tm) != 0) { + if (!localtime_r(&ts->tv_sec, &tm)) { return -1; } @@ -153,7 +153,7 @@ static int bfs_printf_strftime(CFILE *cfile, const struct bfs_fmt *fmt, const st } struct tm tm; - if (xlocaltime(&ts->tv_sec, &tm) != 0) { + if (!localtime_r(&ts->tv_sec, &tm)) { return -1; } |