Skip to content

Commit a1b67a4

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 aa82340 commit a1b67a4

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
@@ -6134,17 +6134,23 @@ cfg_if! {
61346134
cfg_if! {
61356135
if #[cfg(all(not(target_env = "uclibc"), not(target_env = "ohos")))] {
61366136
extern "C" {
6137+
#[cfg_attr(gnu_file_offset_bits64, link_name = "aio_read64")]
61376138
pub fn aio_read(aiocbp: *mut aiocb) -> c_int;
6139+
#[cfg_attr(gnu_file_offset_bits64, link_name = "aio_write64")]
61386140
pub fn aio_write(aiocbp: *mut aiocb) -> c_int;
61396141
pub fn aio_fsync(op: c_int, aiocbp: *mut aiocb) -> c_int;
6142+
#[cfg_attr(gnu_file_offset_bits64, link_name = "aio_error64")]
61406143
pub fn aio_error(aiocbp: *const aiocb) -> c_int;
6144+
#[cfg_attr(gnu_file_offset_bits64, link_name = "aio_return64")]
61416145
pub fn aio_return(aiocbp: *mut aiocb) -> ssize_t;
61426146
pub fn aio_suspend(
61436147
aiocb_list: *const *const aiocb,
61446148
nitems: c_int,
61456149
timeout: *const crate::timespec,
61466150
) -> c_int;
6151+
#[cfg_attr(gnu_file_offset_bits64, link_name = "aio_cancel64")]
61476152
pub fn aio_cancel(fd: c_int, aiocbp: *mut aiocb) -> c_int;
6153+
#[cfg_attr(gnu_file_offset_bits64, link_name = "lio_listio64")]
61486154
pub fn lio_listio(
61496155
mode: c_int,
61506156
aiocb_list: *const *mut aiocb,
@@ -6158,12 +6164,14 @@ cfg_if! {
61586164
cfg_if! {
61596165
if #[cfg(not(target_env = "uclibc"))] {
61606166
extern "C" {
6167+
#[cfg_attr(gnu_file_offset_bits64, link_name = "pwritev64")]
61616168
pub fn pwritev(
61626169
fd: c_int,
61636170
iov: *const crate::iovec,
61646171
iovcnt: c_int,
61656172
offset: off_t,
61666173
) -> ssize_t;
6174+
#[cfg_attr(gnu_file_offset_bits64, link_name = "preadv64")]
61676175
pub fn preadv(
61686176
fd: c_int,
61696177
iov: *const crate::iovec,
@@ -6328,7 +6336,9 @@ extern "C" {
63286336
pub fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int;
63296337
pub fn __errno_location() -> *mut c_int;
63306338

6339+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fallocate64")]
63316340
pub fn fallocate(fd: c_int, mode: c_int, offset: off_t, len: off_t) -> c_int;
6341+
#[cfg_attr(gnu_file_offset_bits64, link_name = "posix_fallocate64")]
63326342
pub fn posix_fallocate(fd: c_int, offset: off_t, len: off_t) -> c_int;
63336343
pub fn readahead(fd: c_int, offset: off64_t, count: size_t) -> ssize_t;
63346344
pub fn getxattr(
@@ -6435,12 +6445,14 @@ extern "C" {
64356445
...
64366446
) -> *mut c_void;
64376447

6448+
#[cfg_attr(gnu_file_offset_bits64, link_name = "glob64")]
64386449
pub fn glob(
64396450
pattern: *const c_char,
64406451
flags: c_int,
64416452
errfunc: Option<extern "C" fn(epath: *const c_char, errno: c_int) -> c_int>,
64426453
pglob: *mut crate::glob_t,
64436454
) -> c_int;
6455+
#[cfg_attr(gnu_file_offset_bits64, link_name = "globfree64")]
64446456
pub fn globfree(pglob: *mut crate::glob_t);
64456457

64466458
pub fn posix_madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int;
@@ -6466,6 +6478,7 @@ extern "C" {
64666478
addr: *mut crate::sockaddr,
64676479
addrlen: *mut crate::socklen_t,
64686480
) -> ssize_t;
6481+
#[cfg_attr(gnu_file_offset_bits64, link_name = "mkstemps64")]
64696482
pub fn mkstemps(template: *mut c_char, suffixlen: c_int) -> c_int;
64706483

64716484
pub fn nl_langinfo(item: crate::nl_item) -> *mut c_char;
@@ -6630,6 +6643,7 @@ extern "C" {
66306643
policy: c_int,
66316644
param: *const crate::sched_param,
66326645
) -> c_int;
6646+
#[cfg_attr(gnu_file_offset_bits64, link_name = "sendfile64")]
66336647
pub fn sendfile(out_fd: c_int, in_fd: c_int, offset: *mut off_t, count: size_t) -> ssize_t;
66346648
pub fn sigsuspend(mask: *const crate::sigset_t) -> c_int;
66356649
pub fn getgrgid_r(

src/unix/linux_like/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,9 +1786,12 @@ extern "C" {
17861786
pub fn memalign(align: size_t, size: size_t) -> *mut c_void;
17871787
pub fn setgroups(ngroups: size_t, ptr: *const crate::gid_t) -> c_int;
17881788
pub fn pipe2(fds: *mut c_int, flags: c_int) -> c_int;
1789+
#[cfg_attr(gnu_file_offset_bits64, link_name = "statfs64")]
17891790
pub fn statfs(path: *const c_char, buf: *mut statfs) -> c_int;
1791+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fstatfs64")]
17901792
pub fn fstatfs(fd: c_int, buf: *mut statfs) -> c_int;
17911793
pub fn memrchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
1794+
#[cfg_attr(gnu_file_offset_bits64, link_name = "posix_fadvise64")]
17921795
pub fn posix_fadvise(fd: c_int, offset: off_t, len: off_t, advise: c_int) -> c_int;
17931796
pub fn futimens(fd: c_int, times: *const crate::timespec) -> c_int;
17941797
pub fn utimensat(
@@ -1886,7 +1889,9 @@ extern "C" {
18861889
) -> size_t;
18871890
pub fn strptime(s: *const c_char, format: *const c_char, tm: *mut crate::tm) -> *mut c_char;
18881891

1892+
#[cfg_attr(gnu_file_offset_bits64, link_name = "mkostemp64")]
18891893
pub fn mkostemp(template: *mut c_char, flags: c_int) -> c_int;
1894+
#[cfg_attr(gnu_file_offset_bits64, link_name = "mkostemps64")]
18901895
pub fn mkostemps(template: *mut c_char, suffixlen: c_int, flags: c_int) -> c_int;
18911896

18921897
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
@@ -577,17 +577,20 @@ extern "C" {
577577
all(target_os = "macos", target_arch = "x86"),
578578
link_name = "fopen$UNIX2003"
579579
)]
580+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fopen64")]
580581
pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE;
581582
#[cfg_attr(
582583
all(target_os = "macos", target_arch = "x86"),
583584
link_name = "freopen$UNIX2003"
584585
)]
586+
#[cfg_attr(gnu_file_offset_bits64, link_name = "freopen64")]
585587
pub fn freopen(filename: *const c_char, mode: *const c_char, file: *mut FILE) -> *mut FILE;
586588

587589
pub fn fflush(file: *mut FILE) -> c_int;
588590
pub fn fclose(file: *mut FILE) -> c_int;
589591
pub fn remove(filename: *const c_char) -> c_int;
590592
pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int;
593+
#[cfg_attr(gnu_file_offset_bits64, link_name = "tmpfile64")]
591594
pub fn tmpfile() -> *mut FILE;
592595
pub fn setvbuf(stream: *mut FILE, buffer: *mut c_char, mode: c_int, size: size_t) -> c_int;
593596
pub fn setbuf(stream: *mut FILE, buf: *mut c_char);
@@ -613,8 +616,10 @@ extern "C" {
613616
pub fn ftell(stream: *mut FILE) -> c_long;
614617
pub fn rewind(stream: *mut FILE);
615618
#[cfg_attr(target_os = "netbsd", link_name = "__fgetpos50")]
619+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fgetpos64")]
616620
pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int;
617621
#[cfg_attr(target_os = "netbsd", link_name = "__fsetpos50")]
622+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fsetpos64")]
618623
pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int;
619624
pub fn feof(stream: *mut FILE) -> c_int;
620625
pub fn ferror(stream: *mut FILE) -> c_int;
@@ -826,6 +831,7 @@ extern "C" {
826831
all(target_os = "freebsd", any(freebsd11, freebsd10)),
827832
link_name = "fstat@FBSD_1.0"
828833
)]
834+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fstat64")]
829835
pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
830836

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

844851
pub fn pclose(stream: *mut crate::FILE) -> c_int;
@@ -853,16 +860,19 @@ extern "C" {
853860
all(target_os = "macos", target_arch = "x86"),
854861
link_name = "open$UNIX2003"
855862
)]
863+
#[cfg_attr(gnu_file_offset_bits64, link_name = "open64")]
856864
pub fn open(path: *const c_char, oflag: c_int, ...) -> c_int;
857865
#[cfg_attr(
858866
all(target_os = "macos", target_arch = "x86"),
859867
link_name = "creat$UNIX2003"
860868
)]
869+
#[cfg_attr(gnu_file_offset_bits64, link_name = "creat64")]
861870
pub fn creat(path: *const c_char, mode: mode_t) -> c_int;
862871
#[cfg_attr(
863872
all(target_os = "macos", target_arch = "x86"),
864873
link_name = "fcntl$UNIX2003"
865874
)]
875+
#[cfg_attr(gnu_file_offset_bits64, link_name = "__fcntl_time64")]
866876
pub fn fcntl(fd: c_int, cmd: c_int, ...) -> c_int;
867877

868878
#[cfg_attr(
@@ -885,6 +895,7 @@ extern "C" {
885895
all(target_os = "freebsd", any(freebsd11, freebsd10)),
886896
link_name = "readdir@FBSD_1.0"
887897
)]
898+
#[cfg_attr(gnu_file_offset_bits64, link_name = "readdir64")]
888899
pub fn readdir(dirp: *mut crate::DIR) -> *mut crate::dirent;
889900
#[cfg_attr(
890901
all(target_os = "macos", target_arch = "x86"),
@@ -923,6 +934,7 @@ extern "C" {
923934
all(target_os = "freebsd", any(freebsd11, freebsd10)),
924935
link_name = "fstatat@FBSD_1.1"
925936
)]
937+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fstatat64")]
926938
pub fn fstatat(dirfd: c_int, pathname: *const c_char, buf: *mut stat, flags: c_int) -> c_int;
927939
pub fn linkat(
928940
olddirfd: c_int,
@@ -992,6 +1004,7 @@ extern "C" {
9921004
pub fn isatty(fd: c_int) -> c_int;
9931005
#[cfg_attr(target_os = "solaris", link_name = "__link_xpg4")]
9941006
pub fn link(src: *const c_char, dst: *const c_char) -> c_int;
1007+
#[cfg_attr(gnu_file_offset_bits64, link_name = "lseek64")]
9951008
pub fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t;
9961009
pub fn pathconf(path: *const c_char, name: c_int) -> c_long;
9971010
pub fn pipe(fds: *mut c_int) -> c_int;
@@ -1054,11 +1067,13 @@ extern "C" {
10541067
all(target_os = "macos", target_arch = "x86"),
10551068
link_name = "pread$UNIX2003"
10561069
)]
1070+
#[cfg_attr(gnu_file_offset_bits64, link_name = "pread64")]
10571071
pub fn pread(fd: c_int, buf: *mut c_void, count: size_t, offset: off_t) -> ssize_t;
10581072
#[cfg_attr(
10591073
all(target_os = "macos", target_arch = "x86"),
10601074
link_name = "pwrite$UNIX2003"
10611075
)]
1076+
#[cfg_attr(gnu_file_offset_bits64, link_name = "pwrite64")]
10621077
pub fn pwrite(fd: c_int, buf: *const c_void, count: size_t, offset: off_t) -> ssize_t;
10631078
pub fn umask(mask: mode_t) -> mode_t;
10641079

@@ -1085,6 +1100,7 @@ extern "C" {
10851100
all(target_os = "macos", target_arch = "x86"),
10861101
link_name = "mmap$UNIX2003"
10871102
)]
1103+
#[cfg_attr(gnu_file_offset_bits64, link_name = "mmap64")]
10881104
pub fn mmap(
10891105
addr: *mut c_void,
10901106
len: size_t,
@@ -1111,6 +1127,7 @@ extern "C" {
11111127
all(target_os = "freebsd", any(freebsd11, freebsd10)),
11121128
link_name = "lstat@FBSD_1.0"
11131129
)]
1130+
#[cfg_attr(gnu_file_offset_bits64, link_name = "lstat64")]
11141131
pub fn lstat(path: *const c_char, buf: *mut stat) -> c_int;
11151132

11161133
#[cfg_attr(
@@ -1133,7 +1150,9 @@ extern "C" {
11331150

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

1153+
#[cfg_attr(gnu_file_offset_bits64, link_name = "truncate64")]
11361154
pub fn truncate(path: *const c_char, length: off_t) -> c_int;
1155+
#[cfg_attr(gnu_file_offset_bits64, link_name = "ftruncate64")]
11371156
pub fn ftruncate(fd: c_int, length: off_t) -> c_int;
11381157

11391158
pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t;
@@ -1438,7 +1457,9 @@ extern "C" {
14381457
pub fn sem_wait(sem: *mut sem_t) -> c_int;
14391458
pub fn sem_trywait(sem: *mut sem_t) -> c_int;
14401459
pub fn sem_post(sem: *mut sem_t) -> c_int;
1460+
#[cfg_attr(gnu_file_offset_bits64, link_name = "statvfs64")]
14411461
pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> c_int;
1462+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fstatvfs64")]
14421463
pub fn fstatvfs(fd: c_int, buf: *mut statvfs) -> c_int;
14431464

14441465
#[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")]
@@ -1462,7 +1483,9 @@ extern "C" {
14621483

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

1486+
#[cfg_attr(gnu_file_offset_bits64, link_name = "fseeko64")]
14651487
pub fn fseeko(stream: *mut crate::FILE, offset: off_t, whence: c_int) -> c_int;
1488+
#[cfg_attr(gnu_file_offset_bits64, link_name = "ftello64")]
14661489
pub fn ftello(stream: *mut crate::FILE) -> off_t;
14671490
#[cfg_attr(
14681491
all(target_os = "macos", target_arch = "x86"),
@@ -1479,6 +1502,7 @@ extern "C" {
14791502
pub fn tcflush(fd: c_int, action: c_int) -> c_int;
14801503
pub fn tcgetsid(fd: c_int) -> crate::pid_t;
14811504
pub fn tcsendbreak(fd: c_int, duration: c_int) -> c_int;
1505+
#[cfg_attr(gnu_file_offset_bits64, link_name = "mkstemp64")]
14821506
pub fn mkstemp(template: *mut c_char) -> c_int;
14831507
pub fn mkdtemp(template: *mut c_char) -> *mut c_char;
14841508

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

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

15081533
}
@@ -1603,6 +1628,7 @@ cfg_if! {
16031628
pub fn pause() -> c_int;
16041629

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

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

0 commit comments

Comments
 (0)