blob: da72665bbde2a40d470f3d3ebb29242f6e85eddb [file] [log] [blame]
Andrew Geissler517393d2023-01-13 08:55:19 -06001From 3ecce665198e3420d70139d86ed22e74804c9379 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Wed, 28 Dec 2022 22:35:55 -0800
4Subject: [PATCH] Do not use LFS64 on linux with musl
5
6glibc is providing open64 and other lfs64 functions but musl aliases
7them to normal equivalents since off_t is always 64-bit on musl,
8therefore check for target env along when target OS is linux before
9using open64, this is more available. Latest Musl has made these
10namespace changes [1]
11
12[1] https://git.musl-libc.org/cgit/musl/commit/?id=246f1c811448f37a44b41cd8df8d0ef9736d95f4
13
14Upstream-Status: Submitted [https://github.com/rust-lang/rust/pull/106246]
15Signed-off-by: Khem Raj <raj.khem@gmail.com>
16---
17 library/std/src/os/linux/fs.rs | 9 ++++++++-
18 library/std/src/sys/unix/fd.rs | 14 ++++++++++----
19 library/std/src/sys/unix/fs.rs | 27 ++++++++++++++++++++-------
20 3 files changed, 38 insertions(+), 12 deletions(-)
21
22diff --git a/library/std/src/os/linux/fs.rs b/library/std/src/os/linux/fs.rs
23index 479bbcc17a8..ab0b2a3eda3 100644
24--- a/library/std/src/os/linux/fs.rs
25+++ b/library/std/src/os/linux/fs.rs
26@@ -329,7 +329,14 @@ pub trait MetadataExt {
27 impl MetadataExt for Metadata {
28 #[allow(deprecated)]
29 fn as_raw_stat(&self) -> &raw::stat {
30- unsafe { &*(self.as_inner().as_inner() as *const libc::stat64 as *const raw::stat) }
31+ #[cfg(target_env = "musl")]
32+ unsafe {
33+ &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat)
34+ }
35+ #[cfg(not(target_env = "musl"))]
36+ unsafe {
37+ &*(self.as_inner().as_inner() as *const libc::stat64 as *const raw::stat)
38+ }
39 }
40 fn st_dev(&self) -> u64 {
41 self.as_inner().as_inner().st_dev as u64
42diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs
43index dbaa3c33e2e..5d31557bd11 100644
44--- a/library/std/src/sys/unix/fd.rs
45+++ b/library/std/src/sys/unix/fd.rs
46@@ -115,9 +115,12 @@ pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> {
47 }
48
49 pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
50- #[cfg(not(any(target_os = "linux", target_os = "android")))]
51+ #[cfg(not(any(
52+ all(target_os = "linux", not(target_env = "musl")),
53+ target_os = "android"
54+ )))]
55 use libc::pread as pread64;
56- #[cfg(any(target_os = "linux", target_os = "android"))]
57+ #[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "android"))]
58 use libc::pread64;
59
60 unsafe {
61@@ -181,9 +184,12 @@ pub fn is_write_vectored(&self) -> bool {
62 }
63
64 pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
65- #[cfg(not(any(target_os = "linux", target_os = "android")))]
66+ #[cfg(not(any(
67+ all(target_os = "linux", not(target_env = "musl")),
68+ target_os = "android"
69+ )))]
70 use libc::pwrite as pwrite64;
71- #[cfg(any(target_os = "linux", target_os = "android"))]
72+ #[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "android"))]
73 use libc::pwrite64;
74
75 unsafe {
76diff --git a/library/std/src/sys/unix/fs.rs b/library/std/src/sys/unix/fs.rs
77index aea0c26ee8b..e7be4729ca6 100644
78--- a/library/std/src/sys/unix/fs.rs
79+++ b/library/std/src/sys/unix/fs.rs
80@@ -45,19 +45,24 @@
81 all(target_os = "linux", target_env = "gnu")
82 ))]
83 use libc::c_char;
84-#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "android"))]
85+#[cfg(any(
86+ all(target_os = "linux", not(target_env = "musl")),
87+ target_os = "emscripten",
88+ target_os = "android"
89+))]
90 use libc::dirfd;
91-#[cfg(any(target_os = "linux", target_os = "emscripten"))]
92+#[cfg(any(not(target_env = "musl"), target_os = "emscripten"))]
93 use libc::fstatat64;
94 #[cfg(any(
95 target_os = "android",
96 target_os = "solaris",
97 target_os = "fuchsia",
98 target_os = "redox",
99- target_os = "illumos"
100+ target_os = "illumos",
101+ target_env = "musl"
102 ))]
103 use libc::readdir as readdir64;
104-#[cfg(target_os = "linux")]
105+#[cfg(all(target_os = "linux", not(target_env = "musl")))]
106 use libc::readdir64;
107 #[cfg(any(target_os = "emscripten", target_os = "l4re"))]
108 use libc::readdir64_r;
109@@ -77,7 +82,13 @@
110 dirent as dirent64, fstat as fstat64, fstatat as fstatat64, ftruncate64, lseek64,
111 lstat as lstat64, off64_t, open as open64, stat as stat64,
112 };
113+#[cfg(target_env = "musl")]
114+use libc::{
115+ dirent as dirent64, fstat as fstat64, ftruncate as ftruncate64, lseek as lseek64,
116+ lstat as lstat64, off_t as off64_t, open as open64, stat as stat64,
117+};
118 #[cfg(not(any(
119+ target_env = "musl",
120 target_os = "linux",
121 target_os = "emscripten",
122 target_os = "l4re",
123@@ -87,7 +98,7 @@
124 dirent as dirent64, fstat as fstat64, ftruncate as ftruncate64, lseek as lseek64,
125 lstat as lstat64, off_t as off64_t, open as open64, stat as stat64,
126 };
127-#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "l4re"))]
128+#[cfg(any(not(target_env = "musl"), target_os = "emscripten", target_os = "l4re"))]
129 use libc::{dirent64, fstat64, ftruncate64, lseek64, lstat64, off64_t, open64, stat64};
130
131 pub use crate::sys_common::fs::try_exists;
132@@ -260,6 +271,7 @@ unsafe impl Sync for Dir {}
133 #[cfg(any(
134 target_os = "android",
135 target_os = "linux",
136+ not(target_env = "musl"),
137 target_os = "solaris",
138 target_os = "illumos",
139 target_os = "fuchsia",
140@@ -292,6 +304,7 @@ struct dirent64_min {
141 }
142
143 #[cfg(not(any(
144+ target_env = "musl",
145 target_os = "android",
146 target_os = "linux",
147 target_os = "solaris",
148@@ -745,7 +758,7 @@ pub fn file_name(&self) -> OsString {
149 }
150
151 #[cfg(all(
152- any(target_os = "linux", target_os = "emscripten", target_os = "android"),
153+ any(not(target_env = "musl"), target_os = "emscripten", target_os = "android"),
154 not(miri)
155 ))]
156 pub fn metadata(&self) -> io::Result<FileAttr> {
157@@ -769,7 +782,7 @@ pub fn metadata(&self) -> io::Result<FileAttr> {
158 }
159
160 #[cfg(any(
161- not(any(target_os = "linux", target_os = "emscripten", target_os = "android")),
162+ not(any(not(target_env = "musl"), target_os = "emscripten", target_os = "android")),
163 miri
164 ))]
165 pub fn metadata(&self) -> io::Result<FileAttr> {
166--
1672.39.0
168