Skip to content

Commit c6a40ea

Browse files
snoggetgross35
authored andcommitted
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. (backport <rust-lang#4345>) (cherry picked from commit 2b4fafb)
1 parent d4fe9e6 commit c6a40ea

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,11 @@ extern "C" {
12001200
pub fn getrlimit64(resource: crate::__rlimit_resource_t, rlim: *mut crate::rlimit64) -> c_int;
12011201
pub fn setrlimit64(resource: crate::__rlimit_resource_t, rlim: *const crate::rlimit64)
12021202
-> c_int;
1203+
#[cfg_attr(gnu_file_offset_bits64, link_name = "getrlimit64")]
12031204
pub fn getrlimit(resource: crate::__rlimit_resource_t, rlim: *mut crate::rlimit) -> c_int;
1205+
#[cfg_attr(gnu_file_offset_bits64, link_name = "setrlimit64")]
12041206
pub fn setrlimit(resource: crate::__rlimit_resource_t, rlim: *const crate::rlimit) -> c_int;
1207+
#[cfg_attr(gnu_file_offset_bits64, link_name = "prlimit64")]
12051208
pub fn prlimit(
12061209
pid: crate::pid_t,
12071210
resource: crate::__rlimit_resource_t,
@@ -1242,13 +1245,15 @@ extern "C" {
12421245
dirfd: c_int,
12431246
path: *const c_char,
12441247
) -> c_int;
1248+
#[cfg_attr(gnu_file_offset_bits64, link_name = "preadv64v2")]
12451249
pub fn preadv2(
12461250
fd: c_int,
12471251
iov: *const crate::iovec,
12481252
iovcnt: c_int,
12491253
offset: off_t,
12501254
flags: c_int,
12511255
) -> ssize_t;
1256+
#[cfg_attr(gnu_file_offset_bits64, link_name = "pwritev64v2")]
12521257
pub fn pwritev2(
12531258
fd: c_int,
12541259
iov: *const crate::iovec,

src/unix/linux_like/linux/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -6300,17 +6300,23 @@ cfg_if! {
63006300
cfg_if! {
63016301
if #[cfg(all(not(target_env = "uclibc"), not(target_env = "ohos")))] {
63026302
extern "C" {
6303+
#[cfg_attr(gnu_file_offset_bits64, link_name = "aio_read64")]
63036304
pub fn aio_read(aiocbp: *mut aiocb) -> c_int;
6305+
#[cfg_attr(gnu_file_offset_bits64, link_name = "aio_write64")]
63046306
pub fn aio_write(aiocbp: *mut aiocb) -> c_int;
63056307
pub fn aio_fsync(op: c_int, aiocbp: *mut aiocb) -> c_int;
6308+
#[cfg_attr(gnu_file_offset_bits64, link_name = "aio_error64")]
63066309
pub fn aio_error(aiocbp: *const aiocb) -> c_int;
6310+
#[cfg_attr(gnu_file_offset_bits64, link_name = "aio_return64")]
63076311
pub fn aio_return(aiocbp: *mut aiocb) -> ssize_t;
63086312
pub fn aio_suspend(
63096313
aiocb_list: *const *const aiocb,
63106314
nitems: c_int,
63116315
timeout: *const crate::timespec,
63126316
) -> c_int;
6317+
#[cfg_attr(gnu_file_offset_bits64, link_name = "aio_cancel64")]
63136318
pub fn aio_cancel(fd: c_int, aiocbp: *mut aiocb) -> c_int;
6319+
#[cfg_attr(gnu_file_offset_bits64, link_name = "lio_listio64")]
63146320
pub fn lio_listio(
63156321
mode: c_int,
63166322
aiocb_list: *const *mut aiocb,
@@ -6324,12 +6330,14 @@ cfg_if! {
63246330
cfg_if! {
63256331
if #[cfg(not(target_env = "uclibc"))] {
63266332
extern "C" {
6333+
#[cfg_attr(gnu_file_offset_bits64, link_name = "pwritev64")]
63276334
pub fn pwritev(
63286335
fd: c_int,
63296336
iov: *const crate::iovec,
63306337
iovcnt: c_int,
63316338
offset: off_t,
63326339
) -> ssize_t;
6340+
#[cfg_attr(gnu_file_offset_bits64, link_name = "preadv64")]
63336341
pub fn preadv(
63346342
fd: c_int,
63356343
iov: *const crate::iovec,
@@ -6494,7 +6502,9 @@ extern "C" {
64946502
pub fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int;
64956503
pub fn __errno_location() -> *mut c_int;
64966504

6505+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fallocate64")]
64976506
pub fn fallocate(fd: c_int, mode: c_int, offset: off_t, len: off_t) -> c_int;
6507+
#[cfg_attr(gnu_file_offset_bits64, link_name = "posix_fallocate64")]
64986508
pub fn posix_fallocate(fd: c_int, offset: off_t, len: off_t) -> c_int;
64996509
pub fn readahead(fd: c_int, offset: off64_t, count: size_t) -> ssize_t;
65006510
pub fn getxattr(
@@ -6601,12 +6611,14 @@ extern "C" {
66016611
...
66026612
) -> *mut c_void;
66036613

6614+
#[cfg_attr(gnu_file_offset_bits64, link_name = "glob64")]
66046615
pub fn glob(
66056616
pattern: *const c_char,
66066617
flags: c_int,
66076618
errfunc: Option<extern "C" fn(epath: *const c_char, errno: c_int) -> c_int>,
66086619
pglob: *mut crate::glob_t,
66096620
) -> c_int;
6621+
#[cfg_attr(gnu_file_offset_bits64, link_name = "globfree64")]
66106622
pub fn globfree(pglob: *mut crate::glob_t);
66116623

66126624
pub fn posix_madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int;
@@ -6632,6 +6644,7 @@ extern "C" {
66326644
addr: *mut crate::sockaddr,
66336645
addrlen: *mut crate::socklen_t,
66346646
) -> ssize_t;
6647+
#[cfg_attr(gnu_file_offset_bits64, link_name = "mkstemps64")]
66356648
pub fn mkstemps(template: *mut c_char, suffixlen: c_int) -> c_int;
66366649

66376650
pub fn nl_langinfo(item: crate::nl_item) -> *mut c_char;
@@ -6796,6 +6809,7 @@ extern "C" {
67966809
policy: c_int,
67976810
param: *const crate::sched_param,
67986811
) -> c_int;
6812+
#[cfg_attr(gnu_file_offset_bits64, link_name = "sendfile64")]
67996813
pub fn sendfile(out_fd: c_int, in_fd: c_int, offset: *mut off_t, count: size_t) -> ssize_t;
68006814
pub fn sigsuspend(mask: *const crate::sigset_t) -> c_int;
68016815
pub fn getgrgid_r(

src/unix/linux_like/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1792,9 +1792,12 @@ extern "C" {
17921792
pub fn memalign(align: size_t, size: size_t) -> *mut c_void;
17931793
pub fn setgroups(ngroups: size_t, ptr: *const crate::gid_t) -> c_int;
17941794
pub fn pipe2(fds: *mut c_int, flags: c_int) -> c_int;
1795+
#[cfg_attr(gnu_file_offset_bits64, link_name = "statfs64")]
17951796
pub fn statfs(path: *const c_char, buf: *mut statfs) -> c_int;
1797+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fstatfs64")]
17961798
pub fn fstatfs(fd: c_int, buf: *mut statfs) -> c_int;
17971799
pub fn memrchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
1800+
#[cfg_attr(gnu_file_offset_bits64, link_name = "posix_fadvise64")]
17981801
pub fn posix_fadvise(fd: c_int, offset: off_t, len: off_t, advise: c_int) -> c_int;
17991802
pub fn futimens(fd: c_int, times: *const crate::timespec) -> c_int;
18001803
pub fn utimensat(
@@ -1900,7 +1903,9 @@ extern "C" {
19001903
) -> size_t;
19011904
pub fn strptime(s: *const c_char, format: *const c_char, tm: *mut crate::tm) -> *mut c_char;
19021905

1906+
#[cfg_attr(gnu_file_offset_bits64, link_name = "mkostemp64")]
19031907
pub fn mkostemp(template: *mut c_char, flags: c_int) -> c_int;
1908+
#[cfg_attr(gnu_file_offset_bits64, link_name = "mkostemps64")]
19041909
pub fn mkostemps(template: *mut c_char, suffixlen: c_int, flags: c_int) -> c_int;
19051910

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

src/unix/mod.rs

+27
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,
@@ -998,6 +1010,7 @@ extern "C" {
9981010
pub fn isatty(fd: c_int) -> c_int;
9991011
#[cfg_attr(target_os = "solaris", link_name = "__link_xpg4")]
10001012
pub fn link(src: *const c_char, dst: *const c_char) -> c_int;
1013+
#[cfg_attr(gnu_file_offset_bits64, link_name = "lseek64")]
10011014
pub fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t;
10021015
pub fn pathconf(path: *const c_char, name: c_int) -> c_long;
10031016
pub fn pipe(fds: *mut c_int) -> c_int;
@@ -1060,11 +1073,13 @@ extern "C" {
10601073
all(target_os = "macos", target_arch = "x86"),
10611074
link_name = "pread$UNIX2003"
10621075
)]
1076+
#[cfg_attr(gnu_file_offset_bits64, link_name = "pread64")]
10631077
pub fn pread(fd: c_int, buf: *mut c_void, count: size_t, offset: off_t) -> ssize_t;
10641078
#[cfg_attr(
10651079
all(target_os = "macos", target_arch = "x86"),
10661080
link_name = "pwrite$UNIX2003"
10671081
)]
1082+
#[cfg_attr(gnu_file_offset_bits64, link_name = "pwrite64")]
10681083
pub fn pwrite(fd: c_int, buf: *const c_void, count: size_t, offset: off_t) -> ssize_t;
10691084
pub fn umask(mask: mode_t) -> mode_t;
10701085

@@ -1091,6 +1106,7 @@ extern "C" {
10911106
all(target_os = "macos", target_arch = "x86"),
10921107
link_name = "mmap$UNIX2003"
10931108
)]
1109+
#[cfg_attr(gnu_file_offset_bits64, link_name = "mmap64")]
10941110
pub fn mmap(
10951111
addr: *mut c_void,
10961112
len: size_t,
@@ -1117,6 +1133,7 @@ extern "C" {
11171133
all(target_os = "freebsd", any(freebsd11, freebsd10)),
11181134
link_name = "lstat@FBSD_1.0"
11191135
)]
1136+
#[cfg_attr(gnu_file_offset_bits64, link_name = "lstat64")]
11201137
pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int;
11211138

11221139
#[cfg_attr(
@@ -1139,7 +1156,9 @@ extern "C" {
11391156

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

1159+
#[cfg_attr(gnu_file_offset_bits64, link_name = "truncate64")]
11421160
pub fn truncate(path: *const c_char, length: off_t) -> c_int;
1161+
#[cfg_attr(gnu_file_offset_bits64, link_name = "ftruncate64")]
11431162
pub fn ftruncate(fd: c_int, length: off_t) -> c_int;
11441163

11451164
pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t;
@@ -1444,7 +1463,9 @@ extern "C" {
14441463
pub fn sem_wait(sem: *mut sem_t) -> c_int;
14451464
pub fn sem_trywait(sem: *mut sem_t) -> c_int;
14461465
pub fn sem_post(sem: *mut sem_t) -> c_int;
1466+
#[cfg_attr(gnu_file_offset_bits64, link_name = "statvfs64")]
14471467
pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> c_int;
1468+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fstatvfs64")]
14481469
pub fn fstatvfs(fd: c_int, buf: *mut statvfs) -> c_int;
14491470

14501471
#[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")]
@@ -1468,7 +1489,9 @@ extern "C" {
14681489

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

1492+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fseeko64")]
14711493
pub fn fseeko(stream: *mut crate::FILE, offset: off_t, whence: c_int) -> c_int;
1494+
#[cfg_attr(gnu_file_offset_bits64, link_name = "ftello64")]
14721495
pub fn ftello(stream: *mut crate::FILE) -> off_t;
14731496
#[cfg_attr(
14741497
all(target_os = "macos", target_arch = "x86"),
@@ -1485,6 +1508,7 @@ extern "C" {
14851508
pub fn tcflush(fd: c_int, action: c_int) -> c_int;
14861509
pub fn tcgetsid(fd: c_int) -> crate::pid_t;
14871510
pub fn tcsendbreak(fd: c_int, duration: c_int) -> c_int;
1511+
#[cfg_attr(gnu_file_offset_bits64, link_name = "mkstemp64")]
14881512
pub fn mkstemp(template: *mut c_char) -> c_int;
14891513
pub fn mkdtemp(template: *mut c_char) -> *mut c_char;
14901514

@@ -1509,6 +1533,7 @@ extern "C" {
15091533
pub fn strcasestr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
15101534
pub fn getline(lineptr: *mut *mut c_char, n: *mut size_t, stream: *mut FILE) -> ssize_t;
15111535

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

15141539
}
@@ -1609,6 +1634,7 @@ cfg_if! {
16091634
pub fn pause() -> c_int;
16101635

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

16141640
#[cfg_attr(
@@ -1637,6 +1663,7 @@ cfg_if! {
16371663
/// https://illumos.org/man/3lib/libc
16381664
/// https://docs.oracle.com/cd/E36784_01/html/E36873/libc-3lib.html
16391665
/// https://www.unix.com/man-page/opensolaris/3LIB/libc/
1666+
#[cfg_attr(gnu_file_offset_bits64, link_name = "readdir64_r")]
16401667
pub fn readdir_r(
16411668
dirp: *mut crate::DIR,
16421669
entry: *mut crate::dirent,

0 commit comments

Comments
 (0)