Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Sources/TSCBasic/WritableByteStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,25 @@ public final class LocalFileOutputByteStream: FileOutputByteStream {
throw error
}
}

#if canImport(Darwin)
/// Disable the SIGPIPE if data is written to this stream after its receiving end has been terminated.
///
/// This can be useful to stop the current process from crashing if it tries to write data to the stdin stream of a
/// subprocess after it has finished or crashed.
///
/// Only available on Darwin because `F_SETNOSIGPIPE` is not universally available.
public func disableSigpipe() throws {
let fileDescriptor = fileno(filePointer)
if fileDescriptor == -1 {
throw FileSystemError(.ioError(code: errno))
}
let fcntlResult = fcntl(fileDescriptor, F_SETNOSIGPIPE, 1)
if fcntlResult == -1 {
throw FileSystemError(.ioError(code: errno))
}
}
#endif
}

/// Public stdout stream instance.
Expand Down