Skip to content

Commit 8542891

Browse files
committed
gnu: Use _FILE_OFFSET_BITS=64 versions of glibc symbols
When _FILE_OFFSET_BITS=64, glibc redirects some function calls to 64 bit versions. These symbols are sometimes the public LFS variants, sometimes hidden variants.
1 parent 3699894 commit 8542891

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,8 +1203,11 @@ extern "C" {
12031203
pub fn getrlimit64(resource: crate::__rlimit_resource_t, rlim: *mut crate::rlimit64) -> c_int;
12041204
pub fn setrlimit64(resource: crate::__rlimit_resource_t, rlim: *const crate::rlimit64)
12051205
-> c_int;
1206+
#[cfg_attr(gnu_file_offset_bits64, link_name = "getrlimit64")]
12061207
pub fn getrlimit(resource: crate::__rlimit_resource_t, rlim: *mut crate::rlimit) -> c_int;
1208+
#[cfg_attr(gnu_file_offset_bits64, link_name = "setrlimit64")]
12071209
pub fn setrlimit(resource: crate::__rlimit_resource_t, rlim: *const crate::rlimit) -> c_int;
1210+
#[cfg_attr(gnu_file_offset_bits64, link_name = "prlimit64")]
12081211
pub fn prlimit(
12091212
pid: crate::pid_t,
12101213
resource: crate::__rlimit_resource_t,
@@ -1245,13 +1248,15 @@ extern "C" {
12451248
dirfd: c_int,
12461249
path: *const c_char,
12471250
) -> c_int;
1251+
#[cfg_attr(gnu_file_offset_bits64, link_name = "preadv64v2")]
12481252
pub fn preadv2(
12491253
fd: c_int,
12501254
iov: *const crate::iovec,
12511255
iovcnt: c_int,
12521256
offset: off_t,
12531257
flags: c_int,
12541258
) -> ssize_t;
1259+
#[cfg_attr(gnu_file_offset_bits64, link_name = "pwritev64v2")]
12551260
pub fn pwritev2(
12561261
fd: c_int,
12571262
iov: *const crate::iovec,

src/unix/linux_like/linux/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6260,17 +6260,23 @@ cfg_if! {
62606260
cfg_if! {
62616261
if #[cfg(all(not(target_env = "uclibc"), not(target_env = "ohos")))] {
62626262
extern "C" {
6263+
#[cfg_attr(gnu_file_offset_bits64, link_name = "aio_read64")]
62636264
pub fn aio_read(aiocbp: *mut aiocb) -> c_int;
6265+
#[cfg_attr(gnu_file_offset_bits64, link_name = "aio_write64")]
62646266
pub fn aio_write(aiocbp: *mut aiocb) -> c_int;
62656267
pub fn aio_fsync(op: c_int, aiocbp: *mut aiocb) -> c_int;
6268+
#[cfg_attr(gnu_file_offset_bits64, link_name = "aio_error64")]
62666269
pub fn aio_error(aiocbp: *const aiocb) -> c_int;
6270+
#[cfg_attr(gnu_file_offset_bits64, link_name = "aio_return64")]
62676271
pub fn aio_return(aiocbp: *mut aiocb) -> ssize_t;
62686272
pub fn aio_suspend(
62696273
aiocb_list: *const *const aiocb,
62706274
nitems: c_int,
62716275
timeout: *const crate::timespec,
62726276
) -> c_int;
6277+
#[cfg_attr(gnu_file_offset_bits64, link_name = "aio_cancel64")]
62736278
pub fn aio_cancel(fd: c_int, aiocbp: *mut aiocb) -> c_int;
6279+
#[cfg_attr(gnu_file_offset_bits64, link_name = "lio_listio64")]
62746280
pub fn lio_listio(
62756281
mode: c_int,
62766282
aiocb_list: *const *mut aiocb,
@@ -6284,12 +6290,14 @@ cfg_if! {
62846290
cfg_if! {
62856291
if #[cfg(not(target_env = "uclibc"))] {
62866292
extern "C" {
6293+
#[cfg_attr(gnu_file_offset_bits64, link_name = "pwritev64")]
62876294
pub fn pwritev(
62886295
fd: c_int,
62896296
iov: *const crate::iovec,
62906297
iovcnt: c_int,
62916298
offset: off_t,
62926299
) -> ssize_t;
6300+
#[cfg_attr(gnu_file_offset_bits64, link_name = "preadv64")]
62936301
pub fn preadv(
62946302
fd: c_int,
62956303
iov: *const crate::iovec,
@@ -6454,7 +6462,9 @@ extern "C" {
64546462
pub fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int;
64556463
pub fn __errno_location() -> *mut c_int;
64566464

6465+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fallocate64")]
64576466
pub fn fallocate(fd: c_int, mode: c_int, offset: off_t, len: off_t) -> c_int;
6467+
#[cfg_attr(gnu_file_offset_bits64, link_name = "posix_fallocate64")]
64586468
pub fn posix_fallocate(fd: c_int, offset: off_t, len: off_t) -> c_int;
64596469
pub fn readahead(fd: c_int, offset: off64_t, count: size_t) -> ssize_t;
64606470
pub fn getxattr(
@@ -6561,12 +6571,14 @@ extern "C" {
65616571
...
65626572
) -> *mut c_void;
65636573

6574+
#[cfg_attr(gnu_file_offset_bits64, link_name = "glob64")]
65646575
pub fn glob(
65656576
pattern: *const c_char,
65666577
flags: c_int,
65676578
errfunc: Option<extern "C" fn(epath: *const c_char, errno: c_int) -> c_int>,
65686579
pglob: *mut crate::glob_t,
65696580
) -> c_int;
6581+
#[cfg_attr(gnu_file_offset_bits64, link_name = "globfree64")]
65706582
pub fn globfree(pglob: *mut crate::glob_t);
65716583

65726584
pub fn posix_madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int;
@@ -6592,6 +6604,7 @@ extern "C" {
65926604
addr: *mut crate::sockaddr,
65936605
addrlen: *mut crate::socklen_t,
65946606
) -> ssize_t;
6607+
#[cfg_attr(gnu_file_offset_bits64, link_name = "mkstemps64")]
65956608
pub fn mkstemps(template: *mut c_char, suffixlen: c_int) -> c_int;
65966609

65976610
pub fn nl_langinfo(item: crate::nl_item) -> *mut c_char;
@@ -6756,6 +6769,7 @@ extern "C" {
67566769
policy: c_int,
67576770
param: *const crate::sched_param,
67586771
) -> c_int;
6772+
#[cfg_attr(gnu_file_offset_bits64, link_name = "sendfile64")]
67596773
pub fn sendfile(out_fd: c_int, in_fd: c_int, offset: *mut off_t, count: size_t) -> ssize_t;
67606774
pub fn sigsuspend(mask: *const crate::sigset_t) -> c_int;
67616775
pub fn getgrgid_r(

src/unix/linux_like/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,9 +1791,12 @@ extern "C" {
17911791
pub fn memalign(align: size_t, size: size_t) -> *mut c_void;
17921792
pub fn setgroups(ngroups: size_t, ptr: *const crate::gid_t) -> c_int;
17931793
pub fn pipe2(fds: *mut c_int, flags: c_int) -> c_int;
1794+
#[cfg_attr(gnu_file_offset_bits64, link_name = "statfs64")]
17941795
pub fn statfs(path: *const c_char, buf: *mut statfs) -> c_int;
1796+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fstatfs64")]
17951797
pub fn fstatfs(fd: c_int, buf: *mut statfs) -> c_int;
17961798
pub fn memrchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
1799+
#[cfg_attr(gnu_file_offset_bits64, link_name = "posix_fadvise64")]
17971800
pub fn posix_fadvise(fd: c_int, offset: off_t, len: off_t, advise: c_int) -> c_int;
17981801
pub fn futimens(fd: c_int, times: *const crate::timespec) -> c_int;
17991802
pub fn utimensat(
@@ -1891,7 +1894,9 @@ extern "C" {
18911894
) -> size_t;
18921895
pub fn strptime(s: *const c_char, format: *const c_char, tm: *mut crate::tm) -> *mut c_char;
18931896

1897+
#[cfg_attr(gnu_file_offset_bits64, link_name = "mkostemp64")]
18941898
pub fn mkostemp(template: *mut c_char, flags: c_int) -> c_int;
1899+
#[cfg_attr(gnu_file_offset_bits64, link_name = "mkostemps64")]
18951900
pub fn mkostemps(template: *mut c_char, suffixlen: c_int, flags: c_int) -> c_int;
18961901

18971902
pub fn getdomainname(name: *mut c_char, len: size_t) -> c_int;

src/unix/mod.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,17 +578,20 @@ extern "C" {
578578
all(target_os = "macos", target_arch = "x86"),
579579
link_name = "fopen$UNIX2003"
580580
)]
581+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fopen64")]
581582
pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE;
582583
#[cfg_attr(
583584
all(target_os = "macos", target_arch = "x86"),
584585
link_name = "freopen$UNIX2003"
585586
)]
587+
#[cfg_attr(gnu_file_offset_bits64, link_name = "freopen64")]
586588
pub fn freopen(filename: *const c_char, mode: *const c_char, file: *mut FILE) -> *mut FILE;
587589

588590
pub fn fflush(file: *mut FILE) -> c_int;
589591
pub fn fclose(file: *mut FILE) -> c_int;
590592
pub fn remove(filename: *const c_char) -> c_int;
591593
pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int;
594+
#[cfg_attr(gnu_file_offset_bits64, link_name = "tmpfile64")]
592595
pub fn tmpfile() -> *mut FILE;
593596
pub fn setvbuf(stream: *mut FILE, buffer: *mut c_char, mode: c_int, size: size_t) -> c_int;
594597
pub fn setbuf(stream: *mut FILE, buf: *mut c_char);
@@ -614,8 +617,10 @@ extern "C" {
614617
pub fn ftell(stream: *mut FILE) -> c_long;
615618
pub fn rewind(stream: *mut FILE);
616619
#[cfg_attr(target_os = "netbsd", link_name = "__fgetpos50")]
620+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fgetpos64")]
617621
pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int;
618622
#[cfg_attr(target_os = "netbsd", link_name = "__fsetpos50")]
623+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fsetpos64")]
619624
pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int;
620625
pub fn feof(stream: *mut FILE) -> c_int;
621626
pub fn ferror(stream: *mut FILE) -> c_int;
@@ -827,6 +832,7 @@ extern "C" {
827832
all(target_os = "freebsd", any(freebsd11, freebsd10)),
828833
link_name = "fstat@FBSD_1.0"
829834
)]
835+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fstat64")]
830836
pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
831837

832838
pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int;
@@ -840,6 +846,7 @@ extern "C" {
840846
all(target_os = "freebsd", any(freebsd11, freebsd10)),
841847
link_name = "stat@FBSD_1.0"
842848
)]
849+
#[cfg_attr(gnu_file_offset_bits64, link_name = "stat64")]
843850
pub fn stat(path: *const c_char, buf: *mut stat) -> c_int;
844851

845852
pub fn pclose(stream: *mut crate::FILE) -> c_int;
@@ -854,16 +861,19 @@ extern "C" {
854861
all(target_os = "macos", target_arch = "x86"),
855862
link_name = "open$UNIX2003"
856863
)]
864+
#[cfg_attr(gnu_file_offset_bits64, link_name = "open64")]
857865
pub fn open(path: *const c_char, oflag: c_int, ...) -> c_int;
858866
#[cfg_attr(
859867
all(target_os = "macos", target_arch = "x86"),
860868
link_name = "creat$UNIX2003"
861869
)]
870+
#[cfg_attr(gnu_file_offset_bits64, link_name = "creat64")]
862871
pub fn creat(path: *const c_char, mode: mode_t) -> c_int;
863872
#[cfg_attr(
864873
all(target_os = "macos", target_arch = "x86"),
865874
link_name = "fcntl$UNIX2003"
866875
)]
876+
#[cfg_attr(gnu_file_offset_bits64, link_name = "__fcntl_time64")]
867877
pub fn fcntl(fd: c_int, cmd: c_int, ...) -> c_int;
868878

869879
#[cfg_attr(
@@ -886,6 +896,7 @@ extern "C" {
886896
all(target_os = "freebsd", any(freebsd11, freebsd10)),
887897
link_name = "readdir@FBSD_1.0"
888898
)]
899+
#[cfg_attr(gnu_file_offset_bits64, link_name = "readdir64")]
889900
pub fn readdir(dirp: *mut crate::DIR) -> *mut crate::dirent;
890901
#[cfg_attr(
891902
all(target_os = "macos", target_arch = "x86"),
@@ -924,6 +935,7 @@ extern "C" {
924935
all(target_os = "freebsd", any(freebsd11, freebsd10)),
925936
link_name = "fstatat@FBSD_1.1"
926937
)]
938+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fstatat64")]
927939
pub fn fstatat(dirfd: c_int, pathname: *const c_char, buf: *mut stat, flags: c_int) -> c_int;
928940
pub fn linkat(
929941
olddirfd: c_int,
@@ -993,6 +1005,7 @@ extern "C" {
9931005
pub fn isatty(fd: c_int) -> c_int;
9941006
#[cfg_attr(target_os = "solaris", link_name = "__link_xpg4")]
9951007
pub fn link(src: *const c_char, dst: *const c_char) -> c_int;
1008+
#[cfg_attr(gnu_file_offset_bits64, link_name = "lseek64")]
9961009
pub fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t;
9971010
pub fn pathconf(path: *const c_char, name: c_int) -> c_long;
9981011
pub fn pipe(fds: *mut c_int) -> c_int;
@@ -1055,11 +1068,13 @@ extern "C" {
10551068
all(target_os = "macos", target_arch = "x86"),
10561069
link_name = "pread$UNIX2003"
10571070
)]
1071+
#[cfg_attr(gnu_file_offset_bits64, link_name = "pread64")]
10581072
pub fn pread(fd: c_int, buf: *mut c_void, count: size_t, offset: off_t) -> ssize_t;
10591073
#[cfg_attr(
10601074
all(target_os = "macos", target_arch = "x86"),
10611075
link_name = "pwrite$UNIX2003"
10621076
)]
1077+
#[cfg_attr(gnu_file_offset_bits64, link_name = "pwrite64")]
10631078
pub fn pwrite(fd: c_int, buf: *const c_void, count: size_t, offset: off_t) -> ssize_t;
10641079
pub fn umask(mask: mode_t) -> mode_t;
10651080

@@ -1086,6 +1101,7 @@ extern "C" {
10861101
all(target_os = "macos", target_arch = "x86"),
10871102
link_name = "mmap$UNIX2003"
10881103
)]
1104+
#[cfg_attr(gnu_file_offset_bits64, link_name = "mmap64")]
10891105
pub fn mmap(
10901106
addr: *mut c_void,
10911107
len: size_t,
@@ -1112,6 +1128,7 @@ extern "C" {
11121128
all(target_os = "freebsd", any(freebsd11, freebsd10)),
11131129
link_name = "lstat@FBSD_1.0"
11141130
)]
1131+
#[cfg_attr(gnu_file_offset_bits64, link_name = "lstat64")]
11151132
pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int;
11161133

11171134
#[cfg_attr(
@@ -1134,7 +1151,9 @@ extern "C" {
11341151

11351152
pub fn symlink(path1: *const c_char, path2: *const c_char) -> c_int;
11361153

1154+
#[cfg_attr(gnu_file_offset_bits64, link_name = "truncate64")]
11371155
pub fn truncate(path: *const c_char, length: off_t) -> c_int;
1156+
#[cfg_attr(gnu_file_offset_bits64, link_name = "ftruncate64")]
11381157
pub fn ftruncate(fd: c_int, length: off_t) -> c_int;
11391158

11401159
pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t;
@@ -1439,7 +1458,9 @@ extern "C" {
14391458
pub fn sem_wait(sem: *mut sem_t) -> c_int;
14401459
pub fn sem_trywait(sem: *mut sem_t) -> c_int;
14411460
pub fn sem_post(sem: *mut sem_t) -> c_int;
1461+
#[cfg_attr(gnu_file_offset_bits64, link_name = "statvfs64")]
14421462
pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> c_int;
1463+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fstatvfs64")]
14431464
pub fn fstatvfs(fd: c_int, buf: *mut statvfs) -> c_int;
14441465

14451466
#[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")]
@@ -1463,7 +1484,9 @@ extern "C" {
14631484

14641485
pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int;
14651486

1487+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fseeko64")]
14661488
pub fn fseeko(stream: *mut crate::FILE, offset: off_t, whence: c_int) -> c_int;
1489+
#[cfg_attr(gnu_file_offset_bits64, link_name = "ftello64")]
14671490
pub fn ftello(stream: *mut crate::FILE) -> off_t;
14681491
#[cfg_attr(
14691492
all(target_os = "macos", target_arch = "x86"),
@@ -1480,6 +1503,7 @@ extern "C" {
14801503
pub fn tcflush(fd: c_int, action: c_int) -> c_int;
14811504
pub fn tcgetsid(fd: c_int) -> crate::pid_t;
14821505
pub fn tcsendbreak(fd: c_int, duration: c_int) -> c_int;
1506+
#[cfg_attr(gnu_file_offset_bits64, link_name = "mkstemp64")]
14831507
pub fn mkstemp(template: *mut c_char) -> c_int;
14841508
pub fn mkdtemp(template: *mut c_char) -> *mut c_char;
14851509

@@ -1504,6 +1528,7 @@ extern "C" {
15041528
pub fn strcasestr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
15051529
pub fn getline(lineptr: *mut *mut c_char, n: *mut size_t, stream: *mut FILE) -> ssize_t;
15061530

1531+
#[cfg_attr(gnu_file_offset_bits64, link_name = "lockf64")]
15071532
pub fn lockf(fd: c_int, cmd: c_int, len: off_t) -> c_int;
15081533

15091534
}
@@ -1604,6 +1629,7 @@ cfg_if! {
16041629
pub fn pause() -> c_int;
16051630

16061631
pub fn mkdirat(dirfd: c_int, pathname: *const c_char, mode: crate::mode_t) -> c_int;
1632+
#[cfg_attr(gnu_file_offset_bits64, link_name = "openat64")]
16071633
pub fn openat(dirfd: c_int, pathname: *const c_char, flags: c_int, ...) -> c_int;
16081634

16091635
#[cfg_attr(
@@ -1632,6 +1658,7 @@ cfg_if! {
16321658
/// https://illumos.org/man/3lib/libc
16331659
/// https://docs.oracle.com/cd/E36784_01/html/E36873/libc-3lib.html
16341660
/// https://www.unix.com/man-page/opensolaris/3LIB/libc/
1661+
#[cfg_attr(gnu_file_offset_bits64, link_name = "readdir64_r")]
16351662
pub fn readdir_r(
16361663
dirp: *mut crate::DIR,
16371664
entry: *mut crate::dirent,

0 commit comments

Comments
 (0)