Skip to content

Commit 74f121b

Browse files
committed
iOS/tvOS/watchOS/visionOS: Fix reading large files
Tested in the iOS simulator with something like: ``` let mut buf = vec![0; c_int::MAX as usize - 1 + 2]; let read_bytes = f.read(&mut buf).unwrap(); ```
1 parent 6333ccf commit 74f121b

File tree

1 file changed

+6
-5
lines changed
  • std/src/sys/pal/unix

1 file changed

+6
-5
lines changed

std/src/sys/pal/unix/fd.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ pub struct FileDesc(OwnedFd);
3333
// with the man page quoting that if the count of bytes to read is
3434
// greater than `SSIZE_MAX` the result is "unspecified".
3535
//
36-
// On macOS, however, apparently the 64-bit libc is either buggy or
36+
// On Apple targets however, apparently the 64-bit libc is either buggy or
3737
// intentionally showing odd behavior by rejecting any read with a size
3838
// larger than or equal to INT_MAX. To handle both of these the read
3939
// size is capped on both platforms.
40-
#[cfg(target_os = "macos")]
41-
const READ_LIMIT: usize = libc::c_int::MAX as usize - 1;
42-
#[cfg(not(target_os = "macos"))]
43-
const READ_LIMIT: usize = libc::ssize_t::MAX as usize;
40+
const READ_LIMIT: usize = if cfg!(target_vendor = "apple") {
41+
libc::c_int::MAX as usize - 1
42+
} else {
43+
libc::ssize_t::MAX as usize
44+
};
4445

4546
#[cfg(any(
4647
target_os = "dragonfly",

0 commit comments

Comments
 (0)