mirror of
https://github.com/apple/swift-system
synced 2026-11-22 04:30:46 +00:00
strerror(3) isn't guaranteed to be thread-safe: for an unknown error number, it may format the message into a static buffer shared by all threads, so concurrent calls to Errno.description could return each other's text. Add a csystem_strerror_r shim to CSystem that writes into a caller-provided buffer. It hides the difference between the XSI strerror_r (Darwin, BSDs, musl, WASI) and the GNU variant that glibc and bionic provide under _GNU_SOURCE, and uses strerror_s on Windows. Errno.description now formats into a stack buffer through this shim. Also add tests for Errno.description, which were a TODO. Fixes #156