diff options
| author | Mads Marquart <mads@marquart.dk> | 2024-05-06 07:52:57 +0200 |
|---|---|---|
| committer | Mads Marquart <mads@marquart.dk> | 2024-05-06 08:08:15 +0200 |
| commit | 28622c9e526ea3d1bd31eba546fc73eeb717752a (patch) | |
| tree | 4ff9bc9ab9d787c89962af5c662b56512341b84f | |
| parent | 53bd38b7c5d5dc43feced7cf76904fa5b788de0c (diff) | |
| download | rust-28622c9e526ea3d1bd31eba546fc73eeb717752a.tar.gz rust-28622c9e526ea3d1bd31eba546fc73eeb717752a.zip | |
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(); ```
| -rw-r--r-- | library/std/src/sys/pal/unix/fd.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/library/std/src/sys/pal/unix/fd.rs b/library/std/src/sys/pal/unix/fd.rs index 203c7180001..1701717db59 100644 --- a/library/std/src/sys/pal/unix/fd.rs +++ b/library/std/src/sys/pal/unix/fd.rs @@ -33,14 +33,15 @@ pub struct FileDesc(OwnedFd); // with the man page quoting that if the count of bytes to read is // greater than `SSIZE_MAX` the result is "unspecified". // -// On macOS, however, apparently the 64-bit libc is either buggy or +// On Apple targets however, apparently the 64-bit libc is either buggy or // intentionally showing odd behavior by rejecting any read with a size // larger than or equal to INT_MAX. To handle both of these the read // size is capped on both platforms. -#[cfg(target_os = "macos")] -const READ_LIMIT: usize = libc::c_int::MAX as usize - 1; -#[cfg(not(target_os = "macos"))] -const READ_LIMIT: usize = libc::ssize_t::MAX as usize; +const READ_LIMIT: usize = if cfg!(target_vendor = "apple") { + libc::c_int::MAX as usize - 1 +} else { + libc::ssize_t::MAX as usize +}; #[cfg(any( target_os = "dragonfly", |
