Use realpath for /etc/localtime symlink resolution
libstdc++ now uses realpath to resolve /etc/localtime symlinks, correctly identifying time zone names.
Libstdc++‘s timezone database now uses realpath to resolve the /etc/localtime symlink, addressing an issue where chained symlinks could prevent correct timezone identification. This change ensures that even complex symlink configurations correctly resolve to the underlying timezone file, allowing chrono::current_zone() to function reliably. The previous readlink-based approach could fail if /etc/localtime pointed to another symlink.
In Details
The chrono::tzdb implementation in libstdc++ previously used readlink to resolve /etc/localtime. This fails when /etc/localtime is a symlink to another symlink (e.g., on read-only /etc mounts). This commit replaces readlink with realpath (or filesystem::canonical as a fallback) to fully resolve all symlinks to a physical file, extracting the correct timezone name. It also removes manual handling of redundant slashes, as realpath handles this. A potential downside is that entirely dangling symlinks might now cause current_zone() to fail instead of attempting to derive a z…
- libstdc++
- The standard C++ library implementation used by GCC.
- realpath
- A system call that returns the canonicalized absolute pathname of a given path, resolving all symbolic links and.. components.
- symlink
- Symbolic Link. A type of file that acts as a pointer to another file or directory. When a symlink is accessed, the operating system follows the link to its target.
- chrono
- A C++ library (in the <chrono> header) providing types and functions for measuring, representing, and manipulating time.
- tzdb
- Time Zone Database. A database containing information about time zones worldwide, including historical data and daylight saving rules.
- current_zone()
- A function within the C++ chrono library that attempts to determine and return the current system's time zone information.