casaroli opened a new pull request, #21099:
URL: https://github.com/apache/nuttx/pull/21099
## Summary
Without the environment variable `TZ`, `tzset()` returned at once, so
`localtime()` always gave UTC: the tzcode default name `TZDEFAULT`
("localtime") was never used. Systems with the IANA TZ database take the local
zone from `/etc/localtime`, a link to the file of the zone.
This PR adds `CONFIG_LIBC_TZDEFAULT`: the time zone file that `tzset()`
loads when `TZ` is not set, an absolute path or a name in `CONFIG_LIBC_TZDIR`.
When the file cannot be read, the local time is UTC. As in the tzcode,
`g_lcl_isset` is -1 while this default zone is in use, so that a later
`tzset()` without `TZ` does not load the file again, and a `TZ` that is set
later still takes effect. The second commit describes the order (`TZ`, the
default file, UTC) and the settings for the IANA layout in
`Documentation/os/libs/libc/zoneinfo.rst`.
## Impact
The default of `CONFIG_LIBC_TZDEFAULT` is empty: without `TZ` the local time
stays UTC, so existing configurations do not change. Only builds with
`CONFIG_LIBC_LOCALTIME`; all build modes.
## Testing
Tested on master aeab6fbf989 and on this PR rebased on it.
Test program `tzdflt.c` on `qemu-armv8a:knsh` (QEMU with HVF) with
`CONFIG_LIBC_LOCALTIME=y`, `CONFIG_LIBC_TZDIR="/system/zoneinfo"` and
`CONFIG_LIBC_TZDEFAULT="/system/zoneinfo/Europe/Rome"` (the TZif file of the
host in the shared `/system` directory). 2026-07-01 12:00 UTC must be 14:00
CEST without `TZ`.
| Case | master | this PR |
|---|---|---|
| `TZ` not set | 12:00, `tzname` empty | 14:00, CET/CEST |
| `TZ=UTC0` | 12:00 | 12:00 |
| `TZ` not set again | 12:00 (UTC0 stays) | 14:00, CET/CEST |
| ostest, `qemu-armv8a:knsh` and `qemu-armv8a:nsh` | status 0 | status 0 |
Build with `CONFIG_LIBC_LOCALTIME` and
`CONFIG_LIBC_TZDEFAULT="/etc/localtime"`, each OK: `rv-virt:nsh64` (flat,
rv64), `rv-virt:pnsh64` (protected, rv64), `rv-virt:knsh64` (kernel, rv64); and
`qemu-armv8a:nsh` (flat, arm64), `qemu-armv8a:knsh` (kernel, arm64) with the
test settings above.
`tools/checkpatch.sh -c -u -m -g` passes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]