Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 1 | From df423041e070dc30b835ecfea7181914e834e33d Mon Sep 17 00:00:00 2001 |
| 2 | From: git-bruh <e817509a-8ee9-4332-b0ad-3a6bdf9ab63f@aleeas.com> |
| 3 | Date: Tue, 19 Sep 2023 19:47:50 +0530 |
| 4 | Subject: [PATCH] Don't use LFS64 symbols on musl |
| 5 | |
| 6 | Simplify #[cfg] blocks |
| 7 | |
| 8 | fmt |
| 9 | |
| 10 | don't try to use the more appropriate direntry on musl |
| 11 | |
| 12 | Upstream-Status: Backport [https://github.com/rust-lang/rust/pull/115968/commits/7a504cc68a56bfaa7855016c81ced9e6b1320fc5] |
| 13 | Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com> |
| 14 | --- |
| 15 | library/std/src/os/linux/fs.rs | 9 ++++++++- |
| 16 | library/std/src/sys/unix/fd.rs | 24 ++++++++++++++++++++---- |
| 17 | library/std/src/sys/unix/fs.rs | 23 ++++++++++++++--------- |
| 18 | 3 files changed, 42 insertions(+), 14 deletions(-) |
| 19 | |
| 20 | diff --git a/library/std/src/os/linux/fs.rs b/library/std/src/os/linux/fs.rs |
| 21 | index 479bbcc17a89..ab0b2a3eda3f 100644 |
| 22 | --- a/library/std/src/os/linux/fs.rs |
| 23 | +++ b/library/std/src/os/linux/fs.rs |
| 24 | @@ -329,7 +329,14 @@ pub trait MetadataExt { |
| 25 | impl MetadataExt for Metadata { |
| 26 | #[allow(deprecated)] |
| 27 | fn as_raw_stat(&self) -> &raw::stat { |
| 28 | - unsafe { &*(self.as_inner().as_inner() as *const libc::stat64 as *const raw::stat) } |
| 29 | + #[cfg(target_env = "musl")] |
| 30 | + unsafe { |
| 31 | + &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat) |
| 32 | + } |
| 33 | + #[cfg(not(target_env = "musl"))] |
| 34 | + unsafe { |
| 35 | + &*(self.as_inner().as_inner() as *const libc::stat64 as *const raw::stat) |
| 36 | + } |
| 37 | } |
| 38 | fn st_dev(&self) -> u64 { |
| 39 | self.as_inner().as_inner().st_dev as u64 |
| 40 | diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs |
| 41 | index 6c4f408426a9..bf1fb3123c4c 100644 |
| 42 | --- a/library/std/src/sys/unix/fd.rs |
| 43 | +++ b/library/std/src/sys/unix/fd.rs |
| 44 | @@ -126,9 +126,17 @@ pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> { |
| 45 | } |
| 46 | |
| 47 | pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> { |
| 48 | - #[cfg(not(any(target_os = "linux", target_os = "android", target_os = "hurd")))] |
| 49 | + #[cfg(not(any( |
| 50 | + all(target_os = "linux", not(target_env = "musl")), |
| 51 | + target_os = "android", |
| 52 | + target_os = "hurd" |
| 53 | + )))] |
| 54 | use libc::pread as pread64; |
| 55 | - #[cfg(any(target_os = "linux", target_os = "android", target_os = "hurd"))] |
| 56 | + #[cfg(any( |
| 57 | + all(target_os = "linux", not(target_env = "musl")), |
| 58 | + target_os = "android", |
| 59 | + target_os = "hurd" |
| 60 | + ))] |
| 61 | use libc::pread64; |
| 62 | |
| 63 | unsafe { |
| 64 | @@ -285,9 +293,17 @@ pub fn is_write_vectored(&self) -> bool { |
| 65 | } |
| 66 | |
| 67 | pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> { |
| 68 | - #[cfg(not(any(target_os = "linux", target_os = "android", target_os = "hurd")))] |
| 69 | + #[cfg(not(any( |
| 70 | + all(target_os = "linux", not(target_env = "musl")), |
| 71 | + target_os = "android", |
| 72 | + target_os = "hurd" |
| 73 | + )))] |
| 74 | use libc::pwrite as pwrite64; |
| 75 | - #[cfg(any(target_os = "linux", target_os = "android", target_os = "hurd"))] |
| 76 | + #[cfg(any( |
| 77 | + all(target_os = "linux", not(target_env = "musl")), |
| 78 | + target_os = "android", |
| 79 | + target_os = "hurd" |
| 80 | + ))] |
| 81 | use libc::pwrite64; |
| 82 | |
| 83 | unsafe { |
| 84 | diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs |
| 85 | index 764e1f257901..b61554098531 100644 |
| 86 | --- a/library/std/src/sys/unix/fs.rs |
| 87 | +++ b/library/std/src/sys/unix/fs.rs |
| 88 | @@ -40,13 +40,17 @@ |
| 89 | ))] |
| 90 | use libc::c_char; |
| 91 | #[cfg(any( |
| 92 | - target_os = "linux", |
| 93 | + all(target_os = "linux", not(target_env = "musl")), |
| 94 | target_os = "emscripten", |
| 95 | target_os = "android", |
| 96 | - target_os = "hurd", |
| 97 | + target_os = "hurd" |
| 98 | ))] |
| 99 | use libc::dirfd; |
| 100 | -#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "hurd"))] |
| 101 | +#[cfg(any( |
| 102 | + all(target_os = "linux", not(target_env = "musl")), |
| 103 | + target_os = "emscripten", |
| 104 | + target_os = "hurd" |
| 105 | +))] |
| 106 | use libc::fstatat64; |
| 107 | #[cfg(any( |
| 108 | target_os = "android", |
| 109 | @@ -56,9 +60,10 @@ |
| 110 | target_os = "illumos", |
| 111 | target_os = "nto", |
| 112 | target_os = "vita", |
| 113 | + all(target_os = "linux", target_env = "musl"), |
| 114 | ))] |
| 115 | use libc::readdir as readdir64; |
| 116 | -#[cfg(any(target_os = "linux", target_os = "hurd"))] |
| 117 | +#[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "hurd"))] |
| 118 | use libc::readdir64; |
| 119 | #[cfg(any(target_os = "emscripten", target_os = "l4re"))] |
| 120 | use libc::readdir64_r; |
| 121 | @@ -82,7 +87,7 @@ |
| 122 | lstat as lstat64, off64_t, open as open64, stat as stat64, |
| 123 | }; |
| 124 | #[cfg(not(any( |
| 125 | - target_os = "linux", |
| 126 | + all(target_os = "linux", not(target_env = "musl")), |
| 127 | target_os = "emscripten", |
| 128 | target_os = "l4re", |
| 129 | target_os = "android", |
| 130 | @@ -93,7 +98,7 @@ |
| 131 | lstat as lstat64, off_t as off64_t, open as open64, stat as stat64, |
| 132 | }; |
| 133 | #[cfg(any( |
| 134 | - target_os = "linux", |
| 135 | + all(target_os = "linux", not(target_env = "musl")), |
| 136 | target_os = "emscripten", |
| 137 | target_os = "l4re", |
| 138 | target_os = "hurd" |
| 139 | @@ -829,10 +834,10 @@ pub fn file_name(&self) -> OsString { |
| 140 | |
| 141 | #[cfg(all( |
| 142 | any( |
| 143 | - target_os = "linux", |
| 144 | + all(target_os = "linux", not(target_env = "musl")), |
| 145 | target_os = "emscripten", |
| 146 | target_os = "android", |
| 147 | - target_os = "hurd", |
| 148 | + target_os = "hurd" |
| 149 | ), |
| 150 | not(miri) |
| 151 | ))] |
| 152 | @@ -858,7 +863,7 @@ pub fn metadata(&self) -> io::Result<FileAttr> { |
| 153 | |
| 154 | #[cfg(any( |
| 155 | not(any( |
| 156 | - target_os = "linux", |
| 157 | + all(target_os = "linux", not(target_env = "musl")), |
| 158 | target_os = "emscripten", |
| 159 | target_os = "android", |
| 160 | target_os = "hurd", |
| 161 | -- |
| 162 | 2.39.0 |
| 163 | |