Skip to content

Commit 090d109

Browse files
committed
Make retryOnInterrupt always explicit internally
1 parent 603718e commit 090d109

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

Sources/System/FileOperations.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extension FileDescriptor {
7070
_ mode: FileDescriptor.AccessMode,
7171
options: FileDescriptor.OpenOptions,
7272
permissions: FilePermissions?,
73-
retryOnInterrupt: Bool = true
73+
retryOnInterrupt: Bool
7474
) -> Result<FileDescriptor, Errno> {
7575
let oFlag = mode.rawValue | options.rawValue
7676
let descOrError: Result<CInt, Errno> = valueOrErrno(retryOnInterrupt: retryOnInterrupt) {
@@ -96,7 +96,7 @@ extension FileDescriptor {
9696

9797
@usableFromInline
9898
internal func _close() -> Result<(), Errno> {
99-
nothingOrErrno(system_close(self.rawValue))
99+
nothingOrErrno(retryOnInterrupt: false) { system_close(self.rawValue) }
100100
}
101101

102102
/// Reposition the offset for the given file descriptor.
@@ -120,8 +120,9 @@ extension FileDescriptor {
120120
internal func _seek(
121121
offset: Int64, from whence: FileDescriptor.SeekOrigin
122122
) -> Result<Int64, Errno> {
123-
let newOffset = system_lseek(self.rawValue, _COffT(offset), whence.rawValue)
124-
return valueOrErrno(Int64(newOffset))
123+
valueOrErrno(retryOnInterrupt: false) {
124+
Int64(system_lseek(self.rawValue, _COffT(offset), whence.rawValue))
125+
}
125126
}
126127

127128

@@ -163,7 +164,7 @@ extension FileDescriptor {
163164
@usableFromInline
164165
internal func _read(
165166
into buffer: UnsafeMutableRawBufferPointer,
166-
retryOnInterrupt: Bool = true
167+
retryOnInterrupt: Bool
167168
) throws -> Result<Int, Errno> {
168169
valueOrErrno(retryOnInterrupt: retryOnInterrupt) {
169170
system_read(self.rawValue, buffer.baseAddress, buffer.count)

Sources/System/Util.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
// Results in errno if i == -1
1111
// @available(macOS 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
12-
internal func valueOrErrno<I: FixedWidthInteger>(
12+
private func valueOrErrno<I: FixedWidthInteger>(
1313
_ i: I
1414
) -> Result<I, Errno> {
1515
i == -1 ? .failure(Errno.current) : .success(i)
1616
}
1717

1818
// @available(macOS 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
19-
internal func nothingOrErrno<I: FixedWidthInteger>(
19+
private func nothingOrErrno<I: FixedWidthInteger>(
2020
_ i: I
2121
) -> Result<(), Errno> {
2222
valueOrErrno(i).map { _ in () }
@@ -36,6 +36,13 @@ internal func valueOrErrno<I: FixedWidthInteger>(
3636
} while true
3737
}
3838

39+
// @available(macOS 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
40+
internal func nothingOrErrno<I: FixedWidthInteger>(
41+
retryOnInterrupt: Bool, _ f: () -> I
42+
) -> Result<(), Errno> {
43+
valueOrErrno(retryOnInterrupt: retryOnInterrupt, f).map { _ in () }
44+
}
45+
3946
// Run a precondition for debug client builds
4047
internal func _debugPrecondition(
4148
_ condition: @autoclosure () -> Bool,

0 commit comments

Comments
 (0)