Fix libstdc++ tests that open FIFOs with O_RDWR.
libstdc++ tests avoid undefined behavior by opening FIFOs with correct access modes.
This commit addresses issues in libstdc++ tests that opened FIFOs with ios_base::in|ios_base::out (equivalent to O_RDWR). POSIX explicitly states the result is undefined when O_RDWR is applied to a FIFO. This commit changes the tests to open FIFOs with the necessary access mode only (read-only or write-only), preventing deadlocks and ensuring correct behavior on systems that strictly follow the POSIX standard.
In Details
Tests in libstdc++'s 27_io directory opened FIFOs using ios_base::in | ios_base::out, which maps to O_RDWR. POSIX leaves the behavior of O_RDWR on FIFOs undefined. On systems that do not permit this, the open() call fails, causing deadlocks as the peer process blocks indefinitely. This commit modifies the tests to use ios_base::in or ios_base::out as appropriate, resolving the undefined behavior and deadlocks. It also corrects a related test case for basic_filebuf::close() that was regressed by a prior change to file mode handling.
- FIFO
- A First-In, First-Out (FIFO) special file, also known as a named pipe. It allows unidirectional inter-process communication.
- O_RDWR
- A file access mode flag that opens a file for both reading and writing.
- POSIX
- The Portable Operating System Interface, a family of standards specified by the IEEE for maintaining compatibility between operating systems.
- ios_base::in
- A stream state flag indicating that the stream is open for input (reading).
- ios_base::out
- A stream state flag indicating that the stream is open for output (writing).
- basic_filebuf
- A stream buffer class in libstdc++ that handles input and output operations for files.