Files
swift-nio/Sources/_NIOFileSystem/Internal
MOHAMMED WASIM KHAN 3777a70115 Fallback to non-positional read/write on ENXIO (#3671)
This PR addresses **#3613** where writing to `/dev/stdout` fails with
`ENXIO (6) Device not configured` when running in a terminal environment
instead of a pipe.

Currently, `SystemFileHandle` checks for `errno == .illegalSeek`
(ESPIPE) when deciding whether to fall back from positional
`pwrite`/`pread` to non-positional `write`/`read` for unseekable files
like pipes. However, macOS/Darwin returns `ENXIO`
(`Errno.noSuchDeviceOrAddress`) instead of `ESPIPE` when attempting a
positional write/read on a terminal device.

**Changes:**
- Added `.noSuchDeviceOrAddress` to the fallback conditions in
`SystemFileHandle.swift` for both `readChunk` and `write`.
- Updated `FileSystemError+Syscall.swift` to map
`.noSuchDeviceOrAddress` to `.unsupported` alongside `.illegalSeek`.
- Replicated these changes across both the `_NIOFileSystem` and `NIOFS`
modules.

This allows `FileSystem.shared.withFileHandle` and other APIs to work
transparently with terminal devices like `/dev/stdout`!
2026-07-22 17:55:38 +01:00
..