https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102259
--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jonathan Wakely <r...@gcc.gnu.org>: https://gcc.gnu.org/g:4065bf7c2c61dd6eb19fdccbcda99000d8e44b7a commit r15-6049-g4065bf7c2c61dd6eb19fdccbcda99000d8e44b7a Author: Jonathan Wakely <jwak...@redhat.com> Date: Fri Dec 6 17:41:01 2024 +0000 libstdc++: Add workaround for read(2) EINVAL on macOS and FreeBSD [PR102259] On macOS and FreeBSD the read(2) system call can return EINVAL for large sizes, so limit the maximum that we try to read. The calling code in basic_filebuf::xsgetn will loop until it gets the size it wants, so we don't need to loop in basic_file::xsgetn, just limit the maximum size. libstdc++-v3/ChangeLog: PR libstdc++/102259 * config/io/basic_file_stdio.cc (basic_file::xsgetn): Limit n to _GLIBCXX_MAX_READ_SIZE if that macro is defined. * config/os/bsd/darwin/os_defines.h (_GLIBCXX_MAX_READ_SIZE): Define to INT_MAX-1. * config/os/bsd/freebsd/os_defines.h (_GLIBCXX_MAX_READ_SIZE): Likewise.