Skip to content

Commit 67695e1

Browse files
committed
Move musl-exclusions to cfg_if blocks and alias types on Musl too
1 parent 394d27d commit 67695e1

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

29812981
t if t.ends_with("_t") => t.to_string(),
29822982

2983-
// In MUSL `flock64` is a typedef to `flock`.
2983+
// In MUSL `xxx64` is a typedef to `xxx`.
29842984
"flock64" if musl => format!("struct {}", ty),
2985+
"dirent64" if musl => format!("struct {}", ty),
2986+
"rlimit64" if musl => format!("struct {}", ty),
2987+
"fpos64_t" if musl => format!("struct {}", ty),
29852988

29862989
// put `struct` in front of all structs:.
29872990
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,
@@ -620,6 +619,17 @@ s! {
620619
}
621620
}
622621

622+
cfg_if! {
623+
if #[cfg(not(target_env = "musl"))] {
624+
s! {
625+
pub struct rlimit64 {
626+
pub rlim_cur: rlim64_t,
627+
pub rlim_max: rlim64_t,
628+
}
629+
}
630+
}
631+
}
632+
623633
s_no_extra_traits! {
624634
pub struct sockaddr_nl {
625635
pub nl_family: ::sa_family_t,
@@ -636,14 +646,6 @@ s_no_extra_traits! {
636646
pub d_name: [::c_char; 256],
637647
}
638648

639-
pub struct dirent64 {
640-
pub d_ino: ::ino64_t,
641-
pub d_off: ::off64_t,
642-
pub d_reclen: ::c_ushort,
643-
pub d_type: ::c_uchar,
644-
pub d_name: [::c_char; 256],
645-
}
646-
647649
pub struct sockaddr_alg {
648650
pub salg_family: ::sa_family_t,
649651
pub salg_type: [::c_uchar; 14],
@@ -733,6 +735,20 @@ s_no_extra_traits! {
733735
}
734736
}
735737

738+
cfg_if! {
739+
if #[cfg(not(target_env = "musl"))] {
740+
s_no_extra_traits! {
741+
pub struct dirent64 {
742+
pub d_ino: ::ino64_t,
743+
pub d_off: ::off64_t,
744+
pub d_reclen: ::c_ushort,
745+
pub d_type: ::c_uchar,
746+
pub d_name: [::c_char; 256],
747+
}
748+
}
749+
}
750+
}
751+
736752
s_no_extra_traits! {
737753
// linux/net_tstamp.h
738754
#[allow(missing_debug_implementations)]
@@ -3852,30 +3868,8 @@ extern "C" {
38523868
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int;
38533869
pub fn __errno_location() -> *mut ::c_int;
38543870

3855-
#[cfg(not(target_env = "musl"))]
3856-
pub fn fopen64(filename: *const c_char, mode: *const c_char) -> *mut ::FILE;
3857-
#[cfg(not(target_env = "musl"))]
3858-
pub fn freopen64(
3859-
filename: *const c_char,
3860-
mode: *const c_char,
3861-
file: *mut ::FILE,
3862-
) -> *mut ::FILE;
3863-
#[cfg(not(target_env = "musl"))]
3864-
pub fn tmpfile64() -> *mut ::FILE;
3865-
#[cfg(not(target_env = "musl"))]
3866-
pub fn fgetpos64(stream: *mut ::FILE, ptr: *mut fpos64_t) -> ::c_int;
3867-
#[cfg(not(target_env = "musl"))]
3868-
pub fn fsetpos64(stream: *mut ::FILE, ptr: *const fpos64_t) -> ::c_int;
3869-
#[cfg(not(target_env = "musl"))]
3870-
pub fn fseeko64(stream: *mut ::FILE, offset: ::off64_t, whence: ::c_int) -> ::c_int;
3871-
#[cfg(not(target_env = "musl"))]
3872-
pub fn ftello64(stream: *mut ::FILE) -> ::off64_t;
38733871
pub fn fallocate(fd: ::c_int, mode: ::c_int, offset: ::off_t, len: ::off_t) -> ::c_int;
3874-
#[cfg(not(target_env = "musl"))]
3875-
pub fn fallocate64(fd: ::c_int, mode: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
38763872
pub fn posix_fallocate(fd: ::c_int, offset: ::off_t, len: ::off_t) -> ::c_int;
3877-
#[cfg(not(target_env = "musl"))]
3878-
pub fn posix_fallocate64(fd: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
38793873
pub fn readahead(fd: ::c_int, offset: ::off64_t, count: ::size_t) -> ::ssize_t;
38803874
pub fn getxattr(
38813875
path: *const c_char,
@@ -4192,13 +4186,6 @@ extern "C" {
41924186
offset: *mut off_t,
41934187
count: ::size_t,
41944188
) -> ::ssize_t;
4195-
#[cfg(not(target_env = "musl"))]
4196-
pub fn sendfile64(
4197-
out_fd: ::c_int,
4198-
in_fd: ::c_int,
4199-
offset: *mut off64_t,
4200-
count: ::size_t,
4201-
) -> ::ssize_t;
42024189
pub fn sigsuspend(mask: *const ::sigset_t) -> ::c_int;
42034190
pub fn getgrgid_r(
42044191
gid: ::gid_t,
@@ -4443,6 +4430,35 @@ extern "C" {
44434430
pub fn pthread_setname_np(thread: ::pthread_t, name: *const ::c_char) -> ::c_int;
44444431
}
44454432

4433+
// LFS64 extensions
4434+
//
4435+
// * musl has 64-bit versions only so aliases the LFS64 symbols to the standard ones
4436+
cfg_if! {
4437+
if #[cfg(not(target_env = "musl"))] {
4438+
extern "C" {
4439+
pub fn fallocate64(fd: ::c_int, mode: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
4440+
pub fn fgetpos64(stream: *mut ::FILE, ptr: *mut fpos64_t) -> ::c_int;
4441+
pub fn fopen64(filename: *const c_char, mode: *const c_char) -> *mut ::FILE;
4442+
pub fn freopen64(
4443+
filename: *const c_char,
4444+
mode: *const c_char,
4445+
file: *mut ::FILE,
4446+
) -> *mut ::FILE;
4447+
pub fn fseeko64(stream: *mut ::FILE, offset: ::off64_t, whence: ::c_int) -> ::c_int;
4448+
pub fn fsetpos64(stream: *mut ::FILE, ptr: *const fpos64_t) -> ::c_int;
4449+
pub fn ftello64(stream: *mut ::FILE) -> ::off64_t;
4450+
pub fn posix_fallocate64(fd: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
4451+
pub fn sendfile64(
4452+
out_fd: ::c_int,
4453+
in_fd: ::c_int,
4454+
offset: *mut off64_t,
4455+
count: ::size_t,
4456+
) -> ::ssize_t;
4457+
pub fn tmpfile64() -> *mut ::FILE;
4458+
}
4459+
}
4460+
}
4461+
44464462
cfg_if! {
44474463
if #[cfg(target_env = "uclibc")] {
44484464
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;
@@ -772,33 +761,71 @@ extern "C" {
772761
pub fn basename(path: *mut ::c_char) -> *mut ::c_char;
773762
}
774763

775-
pub use tmpfile as tmpfile64;
764+
// Musl's standard entrypoints are already LFS64 compatible, historically the library aliased
765+
// these together in header files (as `#define`s) _and_ in the library with weak symbol aliases.
766+
//
767+
// Since <version> these aliases were removed from the library (both in the API and the ABI) so we
768+
// alias them here to keep the crate API stable.
769+
#[allow(dead_code)]
770+
fn check_type_aliases(
771+
dirent: ::dirent,
772+
ino: ::ino_t,
773+
flock: ::flock,
774+
off: ::off_t,
775+
pos: ::fpos_t,
776+
rlimit: ::rlimit,
777+
stat: ::stat,
778+
statfs: ::statfs,
779+
statvfs: ::statvfs,
780+
) {
781+
let _dirent: ::dirent64 = dirent;
782+
let _ino: ::ino64_t = ino;
783+
let _flock: ::flock64 = flock;
784+
let _off: ::off64_t = off;
785+
let _pos: ::fpos64_t = pos;
786+
let _rlimit: ::rlimit64 = rlimit;
787+
let _stat: ::stat64 = stat;
788+
let _statfs: ::statfs64 = statfs;
789+
let _statvfs: ::statvfs64 = statvfs;
790+
}
791+
pub type dirent64 = ::dirent;
792+
pub type fpos64_t = ::fpos_t;
793+
pub type rlimit64 = ::rlimit;
794+
pub type flock64 = ::flock;
795+
pub use creat as creat64;
776796
pub use fallocate as fallocate64;
777797
pub use fgetpos as fgetpos64;
778798
pub use fopen as fopen64;
779799
pub use freopen as freopen64;
780800
pub use fseeko as fseeko64;
781801
pub use fsetpos as fsetpos64;
782-
pub use ftello as ftello64;
783-
pub use posix_fallocate as posix_fallocate64;
784-
pub use sendfile as sendfile64;
785-
pub use statfs as statfs64;
786-
pub use fstatfs as fstatfs64;
787-
pub use statvfs as statvfs64;
788-
pub use fstatvfs as fstatvfs64;
789-
pub use creat as creat64;
790802
pub use fstat as fstat64;
791803
pub use fstatat as fstatat64;
804+
pub use fstatfs as fstatfs64;
805+
pub use fstatvfs as fstatvfs64;
806+
pub use ftello as ftello64;
792807
pub use ftruncate as ftruncate64;
808+
pub use getrlimit as getrlimit64;
793809
pub use lseek as lseek64;
794810
pub use lstat as lstat64;
811+
pub use mmap as mmap64;
795812
pub use open as open64;
796813
pub use openat as openat64;
814+
pub use posix_fadvise as posix_fadvise64;
815+
pub use posix_fallocate as posix_fallocate64;
797816
pub use pread as pread64;
817+
pub use preadv as preadv64;
818+
pub use prlimit as prlimit64;
798819
pub use pwrite as pwrite64;
820+
pub use pwritev as pwritev64;
799821
pub use readdir as readdir64;
800822
pub use readdir_r as readdir64_r;
823+
pub use sendfile as sendfile64;
824+
pub use setrlimit as setrlimit64;
801825
pub use stat as stat64;
826+
pub use statfs as statfs64;
827+
pub use statvfs as statvfs64;
828+
pub use tmpfile as tmpfile64;
802829
pub use truncate as truncate64;
803830

804831
cfg_if! {

0 commit comments

Comments
 (0)