Skip to content

Commit e2355ea

Browse files
committed
Do not use LFS64 on linux with musl
glibc is providing open64 and other lfs64 functions but musl aliases them to normal equivalents since off_t is always 64-bit on musl, therefore check for target env along when target OS is linux before using open64, this is more available. Latest Musl has made these namespace changes [1] [1] https://git.musl-libc.org/cgit/musl/commit/?id=246f1c811448f37a44b41cd8df8d0ef9736d95f4 Signed-off-by: Khem Raj <[email protected]>
1 parent 17a6810 commit e2355ea

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

Diff for: library/std/src/os/linux/fs.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,14 @@ pub trait MetadataExt {
329329
impl MetadataExt for Metadata {
330330
#[allow(deprecated)]
331331
fn as_raw_stat(&self) -> &raw::stat {
332-
unsafe { &*(self.as_inner().as_inner() as *const libc::stat64 as *const raw::stat) }
332+
#[cfg(target_env = "musl")]
333+
unsafe {
334+
&*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat)
335+
}
336+
#[cfg(not(target_env = "musl"))]
337+
unsafe {
338+
&*(self.as_inner().as_inner() as *const libc::stat64 as *const raw::stat)
339+
}
333340
}
334341
fn st_dev(&self) -> u64 {
335342
self.as_inner().as_inner().st_dev as u64

Diff for: library/std/src/sys/unix/fd.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,12 @@ impl FileDesc {
122122
}
123123

124124
pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
125-
#[cfg(not(any(target_os = "linux", target_os = "android")))]
125+
#[cfg(not(any(
126+
all(target_os = "linux", not(target_env = "musl")),
127+
target_os = "android"
128+
)))]
126129
use libc::pread as pread64;
127-
#[cfg(any(target_os = "linux", target_os = "android"))]
130+
#[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "android"))]
128131
use libc::pread64;
129132

130133
unsafe {
@@ -277,9 +280,12 @@ impl FileDesc {
277280
}
278281

279282
pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
280-
#[cfg(not(any(target_os = "linux", target_os = "android")))]
283+
#[cfg(not(any(
284+
all(target_os = "linux", not(target_env = "musl")),
285+
target_os = "android"
286+
)))]
281287
use libc::pwrite as pwrite64;
282-
#[cfg(any(target_os = "linux", target_os = "android"))]
288+
#[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "android"))]
283289
use libc::pwrite64;
284290

285291
unsafe {

Diff for: library/std/src/sys/unix/fs.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ use libc::{c_int, mode_t};
4747
all(target_os = "linux", target_env = "gnu")
4848
))]
4949
use libc::c_char;
50-
#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "android"))]
50+
#[cfg(any(
51+
all(target_os = "linux", not(target_env = "musl")),
52+
target_os = "emscripten",
53+
target_os = "android"
54+
))]
5155
use libc::dirfd;
52-
#[cfg(any(target_os = "linux", target_os = "emscripten"))]
56+
#[cfg(any(not(target_env = "musl"), target_os = "emscripten"))]
5357
use libc::fstatat64;
5458
#[cfg(any(
5559
target_os = "android",
@@ -58,9 +62,10 @@ use libc::fstatat64;
5862
target_os = "redox",
5963
target_os = "illumos",
6064
target_os = "nto",
65+
target_env = "musl",
6166
))]
6267
use libc::readdir as readdir64;
63-
#[cfg(target_os = "linux")]
68+
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
6469
use libc::readdir64;
6570
#[cfg(any(target_os = "emscripten", target_os = "l4re"))]
6671
use libc::readdir64_r;
@@ -81,7 +86,13 @@ use libc::{
8186
dirent as dirent64, fstat as fstat64, fstatat as fstatat64, ftruncate64, lseek64,
8287
lstat as lstat64, off64_t, open as open64, stat as stat64,
8388
};
89+
#[cfg(target_env = "musl")]
90+
use libc::{
91+
dirent as dirent64, fstat as fstat64, ftruncate as ftruncate64, lseek as lseek64,
92+
lstat as lstat64, off_t as off64_t, open as open64, stat as stat64,
93+
};
8494
#[cfg(not(any(
95+
target_env = "musl",
8596
target_os = "linux",
8697
target_os = "emscripten",
8798
target_os = "l4re",
@@ -91,7 +102,7 @@ use libc::{
91102
dirent as dirent64, fstat as fstat64, ftruncate as ftruncate64, lseek as lseek64,
92103
lstat as lstat64, off_t as off64_t, open as open64, stat as stat64,
93104
};
94-
#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "l4re"))]
105+
#[cfg(any(not(target_env = "musl"), target_os = "emscripten", target_os = "l4re"))]
95106
use libc::{dirent64, fstat64, ftruncate64, lseek64, lstat64, off64_t, open64, stat64};
96107

97108
pub use crate::sys_common::fs::try_exists;
@@ -278,6 +289,7 @@ unsafe impl Sync for Dir {}
278289
#[cfg(any(
279290
target_os = "android",
280291
target_os = "linux",
292+
not(target_env = "musl"),
281293
target_os = "solaris",
282294
target_os = "illumos",
283295
target_os = "fuchsia",
@@ -312,6 +324,7 @@ struct dirent64_min {
312324
}
313325

314326
#[cfg(not(any(
327+
target_env = "musl",
315328
target_os = "android",
316329
target_os = "linux",
317330
target_os = "solaris",
@@ -798,7 +811,7 @@ impl DirEntry {
798811
}
799812

800813
#[cfg(all(
801-
any(target_os = "linux", target_os = "emscripten", target_os = "android"),
814+
any(not(target_env = "musl"), target_os = "emscripten", target_os = "android"),
802815
not(miri)
803816
))]
804817
pub fn metadata(&self) -> io::Result<FileAttr> {
@@ -822,7 +835,7 @@ impl DirEntry {
822835
}
823836

824837
#[cfg(any(
825-
not(any(target_os = "linux", target_os = "emscripten", target_os = "android")),
838+
not(any(not(target_env = "musl"), target_os = "emscripten", target_os = "android")),
826839
miri
827840
))]
828841
pub fn metadata(&self) -> io::Result<FileAttr> {

0 commit comments

Comments
 (0)