Skip to content

Commit 328ec95

Browse files
committed
Move musl-exclusions to cfg_if blocks and alias types on Musl too
1 parent 6280e51 commit 328ec95

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
@@ -2941,8 +2941,11 @@ fn test_linux(target: &str) {
29412941

29422942
t if t.ends_with("_t") => t.to_string(),
29432943

2944-
// In MUSL `flock64` is a typedef to `flock`.
2944+
// In MUSL `xxx64` is a typedef to `xxx`.
29452945
"flock64" if musl => format!("struct {}", ty),
2946+
"dirent64" if musl => format!("struct {}", ty),
2947+
"rlimit64" if musl => format!("struct {}", ty),
2948+
"fpos64_t" if musl => format!("struct {}", ty),
29462949

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

src/unix/linux_like/linux/mod.rs

+64-48
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,20 @@ pub type name_t = u64;
4848

4949
pub type iconv_t = *mut ::c_void;
5050

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

6064
s! {
61-
pub struct rlimit64 {
62-
pub rlim_cur: rlim64_t,
63-
pub rlim_max: rlim64_t,
64-
}
65-
6665
pub struct glob_t {
6766
pub gl_pathc: ::size_t,
6867
pub gl_pathv: *mut *mut c_char,
@@ -605,6 +604,17 @@ s! {
605604
}
606605
}
607606

607+
cfg_if! {
608+
if #[cfg(not(target_env = "musl"))] {
609+
s! {
610+
pub struct rlimit64 {
611+
pub rlim_cur: rlim64_t,
612+
pub rlim_max: rlim64_t,
613+
}
614+
}
615+
}
616+
}
617+
608618
s_no_extra_traits! {
609619
pub struct sockaddr_nl {
610620
pub nl_family: ::sa_family_t,
@@ -621,14 +631,6 @@ s_no_extra_traits! {
621631
pub d_name: [::c_char; 256],
622632
}
623633

624-
pub struct dirent64 {
625-
pub d_ino: ::ino64_t,
626-
pub d_off: ::off64_t,
627-
pub d_reclen: ::c_ushort,
628-
pub d_type: ::c_uchar,
629-
pub d_name: [::c_char; 256],
630-
}
631-
632634
pub struct sockaddr_alg {
633635
pub salg_family: ::sa_family_t,
634636
pub salg_type: [::c_uchar; 14],
@@ -692,6 +694,20 @@ s_no_extra_traits! {
692694
}
693695
}
694696

697+
cfg_if! {
698+
if #[cfg(not(target_env = "musl"))] {
699+
s_no_extra_traits! {
700+
pub struct dirent64 {
701+
pub d_ino: ::ino64_t,
702+
pub d_off: ::off64_t,
703+
pub d_reclen: ::c_ushort,
704+
pub d_type: ::c_uchar,
705+
pub d_name: [::c_char; 256],
706+
}
707+
}
708+
}
709+
}
710+
695711
s_no_extra_traits! {
696712
// linux/net_tstamp.h
697713
#[allow(missing_debug_implementations)]
@@ -3764,30 +3780,8 @@ extern "C" {
37643780
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int;
37653781
pub fn __errno_location() -> *mut ::c_int;
37663782

3767-
#[cfg(not(target_env = "musl"))]
3768-
pub fn fopen64(filename: *const c_char, mode: *const c_char) -> *mut ::FILE;
3769-
#[cfg(not(target_env = "musl"))]
3770-
pub fn freopen64(
3771-
filename: *const c_char,
3772-
mode: *const c_char,
3773-
file: *mut ::FILE,
3774-
) -> *mut ::FILE;
3775-
#[cfg(not(target_env = "musl"))]
3776-
pub fn tmpfile64() -> *mut ::FILE;
3777-
#[cfg(not(target_env = "musl"))]
3778-
pub fn fgetpos64(stream: *mut ::FILE, ptr: *mut fpos64_t) -> ::c_int;
3779-
#[cfg(not(target_env = "musl"))]
3780-
pub fn fsetpos64(stream: *mut ::FILE, ptr: *const fpos64_t) -> ::c_int;
3781-
#[cfg(not(target_env = "musl"))]
3782-
pub fn fseeko64(stream: *mut ::FILE, offset: ::off64_t, whence: ::c_int) -> ::c_int;
3783-
#[cfg(not(target_env = "musl"))]
3784-
pub fn ftello64(stream: *mut ::FILE) -> ::off64_t;
37853783
pub fn fallocate(fd: ::c_int, mode: ::c_int, offset: ::off_t, len: ::off_t) -> ::c_int;
3786-
#[cfg(not(target_env = "musl"))]
3787-
pub fn fallocate64(fd: ::c_int, mode: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
37883784
pub fn posix_fallocate(fd: ::c_int, offset: ::off_t, len: ::off_t) -> ::c_int;
3789-
#[cfg(not(target_env = "musl"))]
3790-
pub fn posix_fallocate64(fd: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
37913785
pub fn readahead(fd: ::c_int, offset: ::off64_t, count: ::size_t) -> ::ssize_t;
37923786
pub fn getxattr(
37933787
path: *const c_char,
@@ -4104,13 +4098,6 @@ extern "C" {
41044098
offset: *mut off_t,
41054099
count: ::size_t,
41064100
) -> ::ssize_t;
4107-
#[cfg(not(target_env = "musl"))]
4108-
pub fn sendfile64(
4109-
out_fd: ::c_int,
4110-
in_fd: ::c_int,
4111-
offset: *mut off64_t,
4112-
count: ::size_t,
4113-
) -> ::ssize_t;
41144101
pub fn sigsuspend(mask: *const ::sigset_t) -> ::c_int;
41154102
pub fn getgrgid_r(
41164103
gid: ::gid_t,
@@ -4355,6 +4342,35 @@ extern "C" {
43554342
pub fn pthread_setname_np(thread: ::pthread_t, name: *const ::c_char) -> ::c_int;
43564343
}
43574344

4345+
// LFS64 extensions
4346+
//
4347+
// * musl has 64-bit versions only so aliases the LFS64 symbols to the standard ones
4348+
cfg_if! {
4349+
if #[cfg(not(target_env = "musl"))] {
4350+
extern "C" {
4351+
pub fn fallocate64(fd: ::c_int, mode: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
4352+
pub fn fgetpos64(stream: *mut ::FILE, ptr: *mut fpos64_t) -> ::c_int;
4353+
pub fn fopen64(filename: *const c_char, mode: *const c_char) -> *mut ::FILE;
4354+
pub fn freopen64(
4355+
filename: *const c_char,
4356+
mode: *const c_char,
4357+
file: *mut ::FILE,
4358+
) -> *mut ::FILE;
4359+
pub fn fseeko64(stream: *mut ::FILE, offset: ::off64_t, whence: ::c_int) -> ::c_int;
4360+
pub fn fsetpos64(stream: *mut ::FILE, ptr: *const fpos64_t) -> ::c_int;
4361+
pub fn ftello64(stream: *mut ::FILE) -> ::off64_t;
4362+
pub fn posix_fallocate64(fd: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
4363+
pub fn sendfile64(
4364+
out_fd: ::c_int,
4365+
in_fd: ::c_int,
4366+
offset: *mut off64_t,
4367+
count: ::size_t,
4368+
) -> ::ssize_t;
4369+
pub fn tmpfile64() -> *mut ::FILE;
4370+
}
4371+
}
4372+
}
4373+
43584374
cfg_if! {
43594375
if #[cfg(target_env = "uclibc")] {
43604376
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.
@@ -707,8 +705,6 @@ extern "C" {
707705
timeout: *mut ::timespec,
708706
) -> ::c_int;
709707

710-
pub fn getrlimit64(resource: ::c_int, rlim: *mut ::rlimit64) -> ::c_int;
711-
pub fn setrlimit64(resource: ::c_int, rlim: *const ::rlimit64) -> ::c_int;
712708
pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int;
713709
pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int;
714710
pub fn prlimit(
@@ -717,13 +713,6 @@ extern "C" {
717713
new_limit: *const ::rlimit,
718714
old_limit: *mut ::rlimit,
719715
) -> ::c_int;
720-
pub fn prlimit64(
721-
pid: ::pid_t,
722-
resource: ::c_int,
723-
new_limit: *const ::rlimit64,
724-
old_limit: *mut ::rlimit64,
725-
) -> ::c_int;
726-
727716
pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;
728717
pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int;
729718
pub fn ptrace(request: ::c_int, ...) -> ::c_long;
@@ -756,33 +745,71 @@ extern "C" {
756745
pub fn malloc_usable_size(ptr: *mut ::c_void) -> ::size_t;
757746
}
758747

759-
pub use tmpfile as tmpfile64;
748+
// Musl's standard entrypoints are already LFS64 compatible, historically the library aliased
749+
// these together in header files (as `#define`s) _and_ in the library with weak symbol aliases.
750+
//
751+
// Since <version> these aliases were removed from the library (both in the API and the ABI) so we
752+
// alias them here to keep the crate API stable.
753+
#[allow(dead_code)]
754+
fn check_type_aliases(
755+
dirent: ::dirent,
756+
ino: ::ino_t,
757+
flock: ::flock,
758+
off: ::off_t,
759+
pos: ::fpos_t,
760+
rlimit: ::rlimit,
761+
stat: ::stat,
762+
statfs: ::statfs,
763+
statvfs: ::statvfs,
764+
) {
765+
let _dirent: ::dirent64 = dirent;
766+
let _ino: ::ino64_t = ino;
767+
let _flock: ::flock64 = flock;
768+
let _off: ::off64_t = off;
769+
let _pos: ::fpos64_t = pos;
770+
let _rlimit: ::rlimit64 = rlimit;
771+
let _stat: ::stat64 = stat;
772+
let _statfs: ::statfs64 = statfs;
773+
let _statvfs: ::statvfs64 = statvfs;
774+
}
775+
pub type dirent64 = ::dirent;
776+
pub type fpos64_t = ::fpos_t;
777+
pub type rlimit64 = ::rlimit;
778+
pub type flock64 = ::flock;
779+
pub use creat as creat64;
760780
pub use fallocate as fallocate64;
761781
pub use fgetpos as fgetpos64;
762782
pub use fopen as fopen64;
763783
pub use freopen as freopen64;
764784
pub use fseeko as fseeko64;
765785
pub use fsetpos as fsetpos64;
766-
pub use ftello as ftello64;
767-
pub use posix_fallocate as posix_fallocate64;
768-
pub use sendfile as sendfile64;
769-
pub use statfs as statfs64;
770-
pub use fstatfs as fstatfs64;
771-
pub use statvfs as statvfs64;
772-
pub use fstatvfs as fstatvfs64;
773-
pub use creat as creat64;
774786
pub use fstat as fstat64;
775787
pub use fstatat as fstatat64;
788+
pub use fstatfs as fstatfs64;
789+
pub use fstatvfs as fstatvfs64;
790+
pub use ftello as ftello64;
776791
pub use ftruncate as ftruncate64;
792+
pub use getrlimit as getrlimit64;
777793
pub use lseek as lseek64;
778794
pub use lstat as lstat64;
795+
pub use mmap as mmap64;
779796
pub use open as open64;
780797
pub use openat as openat64;
798+
pub use posix_fadvise as posix_fadvise64;
799+
pub use posix_fallocate as posix_fallocate64;
781800
pub use pread as pread64;
801+
pub use preadv as preadv64;
802+
pub use prlimit as prlimit64;
782803
pub use pwrite as pwrite64;
804+
pub use pwritev as pwritev64;
783805
pub use readdir as readdir64;
784806
pub use readdir_r as readdir64_r;
807+
pub use sendfile as sendfile64;
808+
pub use setrlimit as setrlimit64;
785809
pub use stat as stat64;
810+
pub use statfs as statfs64;
811+
pub use statvfs as statvfs64;
812+
pub use tmpfile as tmpfile64;
786813
pub use truncate as truncate64;
787814

788815
cfg_if! {

0 commit comments

Comments
 (0)