GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
libstdc++

libstdc++: Adjust filesystem::read_symlink error handling on Windows.

Corrected error handling for `std::filesystem::read_symlink` on Windows.

Error handling for std::filesystem::read_symlink on Windows has been adjusted to use std::error_code instead of errno. Helper functions like __open_for_stat and __check_handle_type now accept a std::error_code parameter, and errno is set only within the Windows-specific __stat_windows function. This change ensures consistent error reporting across different platforms and C++ APIs.

In Details

The Windows implementation of std::filesystem::read_symlink incorrectly modified errno in helper functions that are also used by other std::filesystem operations which rely on std::error_code. This commit rectifies this by making the helpers accept std::error_code and moving errno setting to the __stat_windows function, aligning with the expected error reporting mechanism for std::filesystem.

For Context
std::filesystem
A C++ standard library component that provides facilities for manipulating files and directories, including path operations, file status queries, and I/O.
errno
A global integer variable in C and C++ that holds the error code from the last library or system call that failed.
std::error_code
A C++ class used to represent platform-specific error codes, often used by libraries like std::filesystem as an alternative to errno for more localized and type-safe error reporting.
read_symlink
A function within std::filesystem that reads the target of a symbolic link.
Filed Under: filesystemlibstdc++windowserror handling