Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Android: more targeted approach to unusual nullabilities
  • Loading branch information
glessard committed Mar 11, 2024
commit 5ca37e7d3997b00e19d4a77d45db7830b18b6f56
20 changes: 18 additions & 2 deletions Sources/System/Internals/Syscalls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ internal func system_pread(
#if ENABLE_MOCKING
if mockingEnabled { return _mockInt(fd, buf, nbyte, offset) }
#endif
return buf.map({ pread(fd, $0, nbyte, offset) }) ?? 0
#if os(Android)
var zero = UInt8.zero
return withUnsafeMutablePointer(to: &zero) {
// this pread has a non-nullable `buf` pointer
pread(fd, buf ?? UnsafeMutableRawPointer($0), nbyte, offset)
}
#else
return pread(fd, buf, nbyte, offset)
#endif
}

// lseek
Expand Down Expand Up @@ -101,7 +109,15 @@ internal func system_pwrite(
#if ENABLE_MOCKING
if mockingEnabled { return _mockInt(fd, buf, nbyte, offset) }
#endif
return buf.map({ pwrite(fd, $0, nbyte, offset) }) ?? 0
#if os(Android)
var zero = UInt8.zero
return withUnsafeMutablePointer(to: &zero) {
// this pwrite has a non-nullable `buf` pointer
pwrite(fd, buf ?? UnsafeRawPointer($0), nbyte, offset)
}
#else
return pwrite(fd, buf, nbyte, offset)
#endif
}

internal func system_dup(_ fd: Int32) -> Int32 {
Expand Down