Skip to content

Commit b95fbee

Browse files
committed
Move musl-exclusions to cfg_if blocks and alias types on Musl too
1 parent b2d1051 commit b95fbee

File tree

4 files changed

+180
-136
lines changed

4 files changed

+180
-136
lines changed

libc-test/build.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3319,8 +3319,11 @@ fn test_linux(target: &str) {
33193319

33203320
t if t.ends_with("_t") => t.to_string(),
33213321

3322-
// In MUSL `flock64` is a typedef to `flock`.
3322+
// In MUSL `xxx64` is a typedef to `xxx`.
33233323
"flock64" if musl => format!("struct {}", ty),
3324+
"dirent64" if musl => format!("struct {}", ty),
3325+
"rlimit64" if musl => format!("struct {}", ty),
3326+
"fpos64_t" if musl => format!("struct {}", ty),
33243327

33253328
// put `struct` in front of all structs:.
33263329
t if is_struct => format!("struct {}", t),

src/unix/linux_like/linux/mod.rs

+64-48
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,20 @@ pub type iconv_t = *mut ::c_void;
5151
// linux/sctp.h
5252
pub type sctp_assoc_t = ::__s32;
5353

54-
#[cfg_attr(feature = "extra_traits", derive(Debug))]
55-
pub enum fpos64_t {} // FIXME: fill this out with a struct
56-
impl ::Copy for fpos64_t {}
57-
impl ::Clone for fpos64_t {
58-
fn clone(&self) -> fpos64_t {
59-
*self
54+
cfg_if! {
55+
if #[cfg(not(target_env = "musl"))] {
56+
#[cfg_attr(feature = "extra_traits", derive(Debug))]
57+
pub enum fpos64_t {} // FIXME: fill this out with a struct
58+
impl ::Copy for fpos64_t {}
59+
impl ::Clone for fpos64_t {
60+
fn clone(&self) -> fpos64_t {
61+
*self
62+
}
63+
}
6064
}
6165
}
6266

6367
s! {
64-
pub struct rlimit64 {
65-
pub rlim_cur: rlim64_t,
66-
pub rlim_max: rlim64_t,
67-
}
68-
6968
pub struct glob_t {
7069
pub gl_pathc: ::size_t,
7170
pub gl_pathv: *mut *mut c_char,
@@ -687,6 +686,17 @@ s! {
687686
}
688687
}
689688

689+
cfg_if! {
690+
if #[cfg(not(target_env = "musl"))] {
691+
s! {
692+
pub struct rlimit64 {
693+
pub rlim_cur: rlim64_t,
694+
pub rlim_max: rlim64_t,
695+
}
696+
}
697+
}
698+
}
699+
690700
s_no_extra_traits! {
691701
pub struct sockaddr_nl {
692702
pub nl_family: ::sa_family_t,
@@ -703,14 +713,6 @@ s_no_extra_traits! {
703713
pub d_name: [::c_char; 256],
704714
}
705715

706-
pub struct dirent64 {
707-
pub d_ino: ::ino64_t,
708-
pub d_off: ::off64_t,
709-
pub d_reclen: ::c_ushort,
710-
pub d_type: ::c_uchar,
711-
pub d_name: [::c_char; 256],
712-
}
713-
714716
pub struct sockaddr_alg {
715717
pub salg_family: ::sa_family_t,
716718
pub salg_type: [::c_uchar; 14],
@@ -806,6 +808,20 @@ s_no_extra_traits! {
806808
}
807809
}
808810

811+
cfg_if! {
812+
if #[cfg(not(target_env = "musl"))] {
813+
s_no_extra_traits! {
814+
pub struct dirent64 {
815+
pub d_ino: ::ino64_t,
816+
pub d_off: ::off64_t,
817+
pub d_reclen: ::c_ushort,
818+
pub d_type: ::c_uchar,
819+
pub d_name: [::c_char; 256],
820+
}
821+
}
822+
}
823+
}
824+
809825
s_no_extra_traits! {
810826
// linux/net_tstamp.h
811827
#[allow(missing_debug_implementations)]
@@ -4269,30 +4285,8 @@ extern "C" {
42694285
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int;
42704286
pub fn __errno_location() -> *mut ::c_int;
42714287

4272-
#[cfg(not(target_env = "musl"))]
4273-
pub fn fopen64(filename: *const c_char, mode: *const c_char) -> *mut ::FILE;
4274-
#[cfg(not(target_env = "musl"))]
4275-
pub fn freopen64(
4276-
filename: *const c_char,
4277-
mode: *const c_char,
4278-
file: *mut ::FILE,
4279-
) -> *mut ::FILE;
4280-
#[cfg(not(target_env = "musl"))]
4281-
pub fn tmpfile64() -> *mut ::FILE;
4282-
#[cfg(not(target_env = "musl"))]
4283-
pub fn fgetpos64(stream: *mut ::FILE, ptr: *mut fpos64_t) -> ::c_int;
4284-
#[cfg(not(target_env = "musl"))]
4285-
pub fn fsetpos64(stream: *mut ::FILE, ptr: *const fpos64_t) -> ::c_int;
4286-
#[cfg(not(target_env = "musl"))]
4287-
pub fn fseeko64(stream: *mut ::FILE, offset: ::off64_t, whence: ::c_int) -> ::c_int;
4288-
#[cfg(not(target_env = "musl"))]
4289-
pub fn ftello64(stream: *mut ::FILE) -> ::off64_t;
42904288
pub fn fallocate(fd: ::c_int, mode: ::c_int, offset: ::off_t, len: ::off_t) -> ::c_int;
4291-
#[cfg(not(target_env = "musl"))]
4292-
pub fn fallocate64(fd: ::c_int, mode: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
42934289
pub fn posix_fallocate(fd: ::c_int, offset: ::off_t, len: ::off_t) -> ::c_int;
4294-
#[cfg(not(target_env = "musl"))]
4295-
pub fn posix_fallocate64(fd: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
42964290
pub fn readahead(fd: ::c_int, offset: ::off64_t, count: ::size_t) -> ::ssize_t;
42974291
pub fn getxattr(
42984292
path: *const c_char,
@@ -4593,13 +4587,6 @@ extern "C" {
45934587
offset: *mut off_t,
45944588
count: ::size_t,
45954589
) -> ::ssize_t;
4596-
#[cfg(not(target_env = "musl"))]
4597-
pub fn sendfile64(
4598-
out_fd: ::c_int,
4599-
in_fd: ::c_int,
4600-
offset: *mut off64_t,
4601-
count: ::size_t,
4602-
) -> ::ssize_t;
46034590
pub fn sigsuspend(mask: *const ::sigset_t) -> ::c_int;
46044591
pub fn getgrgid_r(
46054592
gid: ::gid_t,
@@ -4851,6 +4838,35 @@ extern "C" {
48514838
) -> ::ssize_t;
48524839
}
48534840

4841+
// LFS64 extensions
4842+
//
4843+
// * musl has 64-bit versions only so aliases the LFS64 symbols to the standard ones
4844+
cfg_if! {
4845+
if #[cfg(not(target_env = "musl"))] {
4846+
extern "C" {
4847+
pub fn fallocate64(fd: ::c_int, mode: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
4848+
pub fn fgetpos64(stream: *mut ::FILE, ptr: *mut fpos64_t) -> ::c_int;
4849+
pub fn fopen64(filename: *const c_char, mode: *const c_char) -> *mut ::FILE;
4850+
pub fn freopen64(
4851+
filename: *const c_char,
4852+
mode: *const c_char,
4853+
file: *mut ::FILE,
4854+
) -> *mut ::FILE;
4855+
pub fn fseeko64(stream: *mut ::FILE, offset: ::off64_t, whence: ::c_int) -> ::c_int;
4856+
pub fn fsetpos64(stream: *mut ::FILE, ptr: *const fpos64_t) -> ::c_int;
4857+
pub fn ftello64(stream: *mut ::FILE) -> ::off64_t;
4858+
pub fn posix_fallocate64(fd: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
4859+
pub fn sendfile64(
4860+
out_fd: ::c_int,
4861+
in_fd: ::c_int,
4862+
offset: *mut off64_t,
4863+
count: ::size_t,
4864+
) -> ::ssize_t;
4865+
pub fn tmpfile64() -> *mut ::FILE;
4866+
}
4867+
}
4868+
}
4869+
48544870
cfg_if! {
48554871
if #[cfg(target_env = "uclibc")] {
48564872
mod uclibc;

src/unix/linux_like/linux/musl/mod.rs

+47-20
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ pub type fsblkcnt_t = ::c_ulonglong;
2222
pub type fsfilcnt_t = ::c_ulonglong;
2323
pub type rlim_t = ::c_ulonglong;
2424

25-
pub type flock64 = flock;
26-
2725
cfg_if! {
2826
if #[cfg(doc)] {
2927
// Used in `linux::arch` to define ioctl constants.
@@ -719,8 +717,6 @@ extern "C" {
719717
timeout: *mut ::timespec,
720718
) -> ::c_int;
721719

722-
pub fn getrlimit64(resource: ::c_int, rlim: *mut ::rlimit64) -> ::c_int;
723-
pub fn setrlimit64(resource: ::c_int, rlim: *const ::rlimit64) -> ::c_int;
724720
pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int;
725721
pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int;
726722
pub fn prlimit(
@@ -729,13 +725,6 @@ extern "C" {
729725
new_limit: *const ::rlimit,
730726
old_limit: *mut ::rlimit,
731727
) -> ::c_int;
732-
pub fn prlimit64(
733-
pid: ::pid_t,
734-
resource: ::c_int,
735-
new_limit: *const ::rlimit64,
736-
old_limit: *mut ::rlimit64,
737-
) -> ::c_int;
738-
739728
pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;
740729
pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int;
741730
pub fn ptrace(request: ::c_int, ...) -> ::c_long;
@@ -784,33 +773,71 @@ extern "C" {
784773
pub fn basename(path: *mut ::c_char) -> *mut ::c_char;
785774
}
786775

787-
pub use tmpfile as tmpfile64;
776+
// Musl's standard entrypoints are already LFS64 compatible, historically the library aliased
777+
// these together in header files (as `#define`s) _and_ in the library with weak symbol aliases.
778+
//
779+
// Since <version> these aliases were removed from the library (both in the API and the ABI) so we
780+
// alias them here to keep the crate API stable.
781+
#[allow(dead_code)]
782+
fn check_type_aliases(
783+
dirent: ::dirent,
784+
ino: ::ino_t,
785+
flock: ::flock,
786+
off: ::off_t,
787+
pos: ::fpos_t,
788+
rlimit: ::rlimit,
789+
stat: ::stat,
790+
statfs: ::statfs,
791+
statvfs: ::statvfs,
792+
) {
793+
let _dirent: ::dirent64 = dirent;
794+
let _ino: ::ino64_t = ino;
795+
let _flock: ::flock64 = flock;
796+
let _off: ::off64_t = off;
797+
let _pos: ::fpos64_t = pos;
798+
let _rlimit: ::rlimit64 = rlimit;
799+
let _stat: ::stat64 = stat;
800+
let _statfs: ::statfs64 = statfs;
801+
let _statvfs: ::statvfs64 = statvfs;
802+
}
803+
pub type dirent64 = ::dirent;
804+
pub type fpos64_t = ::fpos_t;
805+
pub type rlimit64 = ::rlimit;
806+
pub type flock64 = ::flock;
807+
pub use creat as creat64;
788808
pub use fallocate as fallocate64;
789809
pub use fgetpos as fgetpos64;
790810
pub use fopen as fopen64;
791811
pub use freopen as freopen64;
792812
pub use fseeko as fseeko64;
793813
pub use fsetpos as fsetpos64;
794-
pub use ftello as ftello64;
795-
pub use posix_fallocate as posix_fallocate64;
796-
pub use sendfile as sendfile64;
797-
pub use statfs as statfs64;
798-
pub use fstatfs as fstatfs64;
799-
pub use statvfs as statvfs64;
800-
pub use fstatvfs as fstatvfs64;
801-
pub use creat as creat64;
802814
pub use fstat as fstat64;
803815
pub use fstatat as fstatat64;
816+
pub use fstatfs as fstatfs64;
817+
pub use fstatvfs as fstatvfs64;
818+
pub use ftello as ftello64;
804819
pub use ftruncate as ftruncate64;
820+
pub use getrlimit as getrlimit64;
805821
pub use lseek as lseek64;
806822
pub use lstat as lstat64;
823+
pub use mmap as mmap64;
807824
pub use open as open64;
808825
pub use openat as openat64;
826+
pub use posix_fadvise as posix_fadvise64;
827+
pub use posix_fallocate as posix_fallocate64;
809828
pub use pread as pread64;
829+
pub use preadv as preadv64;
830+
pub use prlimit as prlimit64;
810831
pub use pwrite as pwrite64;
832+
pub use pwritev as pwritev64;
811833
pub use readdir as readdir64;
812834
pub use readdir_r as readdir64_r;
835+
pub use sendfile as sendfile64;
836+
pub use setrlimit as setrlimit64;
813837
pub use stat as stat64;
838+
pub use statfs as statfs64;
839+
pub use statvfs as statvfs64;
840+
pub use tmpfile as tmpfile64;
814841
pub use truncate as truncate64;
815842

816843
cfg_if! {

0 commit comments

Comments
 (0)