Skip to content

Commit ff45035

Browse files
committed
Android: add some of the same LFS functions as Linux
Audit the LFS functions from Linux and add the same for Android if bionic supports it, according to libc.map from API 23 (Android 6.0). The standard library is currently limited to API 18, so it may only use `lseek64`, `pread64`, `pwrite64`, `ftruncate64`, and `readahead`. Note that `stat64` and `dirent64` are actually identical to the regular versions, because bionic has always mapped them to the LFS syscalls. It also sets `O_LARGEFILE` at all times, so `open` matches `open64`. Still, the explicit LFS names may be useful to match Linux. Fixes rust-lang#189.
1 parent 403bdc8 commit ff45035

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

src/unix/notbsd/android/mod.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub type time_t = i32;
88
pub type suseconds_t = i32;
99
pub type wchar_t = u32;
1010
pub type off_t = i32;
11+
pub type off64_t = i64;
1112
pub type ino_t = u32;
1213
pub type blkcnt_t = u32;
1314
pub type blksize_t = u32;
@@ -48,6 +49,28 @@ s! {
4849
pub st_ino: ::c_ulonglong,
4950
}
5051

52+
pub struct stat64 {
53+
pub st_dev: ::c_ulonglong,
54+
__pad0: [::c_uchar; 4],
55+
__st_ino: ::ino_t,
56+
pub st_mode: ::c_uint,
57+
pub st_nlink: ::c_uint,
58+
pub st_uid: ::uid_t,
59+
pub st_gid: ::gid_t,
60+
pub st_rdev: ::c_ulonglong,
61+
__pad3: [::c_uchar; 4],
62+
pub st_size: ::c_longlong,
63+
pub st_blksize: blksize_t,
64+
pub st_blocks: ::c_ulonglong,
65+
pub st_atime: ::c_ulong,
66+
pub st_atime_nsec: ::c_ulong,
67+
pub st_mtime: ::c_ulong,
68+
pub st_mtime_nsec: ::c_ulong,
69+
pub st_ctime: ::c_ulong,
70+
pub st_ctime_nsec: ::c_ulong,
71+
pub st_ino: ::c_ulonglong,
72+
}
73+
5174
pub struct dirent {
5275
pub d_ino: u64,
5376
pub d_off: i64,
@@ -56,6 +79,19 @@ s! {
5679
pub d_name: [::c_char; 256],
5780
}
5881

82+
pub struct dirent64 {
83+
pub d_ino: u64,
84+
pub d_off: i64,
85+
pub d_reclen: ::c_ushort,
86+
pub d_type: ::c_uchar,
87+
pub d_name: [::c_char; 256],
88+
}
89+
90+
pub struct rlimit64 {
91+
pub rlim_cur: u64,
92+
pub rlim_max: u64,
93+
}
94+
5995
pub struct pthread_attr_t {
6096
pub flags: ::uint32_t,
6197
pub stack_base: *mut ::c_void,
@@ -588,6 +624,30 @@ extern {
588624
pub fn timegm64(tm: *const ::tm) -> time64_t;
589625
pub fn eventfd(init: ::c_uint, flags: ::c_int) -> ::c_int;
590626
pub fn ptrace(request: ::c_int, ...) -> ::c_long;
627+
pub fn fstat64(fildes: ::c_int, buf: *mut stat64) -> ::c_int;
628+
pub fn stat64(path: *const c_char, buf: *mut stat64) -> ::c_int;
629+
pub fn open64(path: *const c_char, oflag: ::c_int, ...) -> ::c_int;
630+
pub fn creat64(path: *const c_char, mode: mode_t) -> ::c_int;
631+
pub fn lseek64(fd: ::c_int, offset: off64_t, whence: ::c_int) -> off64_t;
632+
pub fn pread64(fd: ::c_int, buf: *mut ::c_void, count: ::size_t,
633+
offset: off64_t) -> ::ssize_t;
634+
pub fn pwrite64(fd: ::c_int, buf: *const ::c_void, count: ::size_t,
635+
offset: off64_t) -> ::ssize_t;
636+
pub fn mmap64(addr: *mut ::c_void,
637+
len: ::size_t,
638+
prot: ::c_int,
639+
flags: ::c_int,
640+
fd: ::c_int,
641+
offset: off64_t)
642+
-> *mut ::c_void;
643+
pub fn lstat64(path: *const c_char, buf: *mut stat64) -> ::c_int;
644+
pub fn ftruncate64(fd: ::c_int, length: off64_t) -> ::c_int;
645+
pub fn readdir64_r(dirp: *mut ::DIR, entry: *mut ::dirent64,
646+
result: *mut *mut ::dirent64) -> ::c_int;
647+
pub fn getrlimit64(resource: ::c_int, rlim: *mut rlimit64) -> ::c_int;
648+
pub fn setrlimit64(resource: ::c_int, rlim: *const rlimit64) -> ::c_int;
649+
pub fn readahead(fd: ::c_int, offset: ::off64_t,
650+
count: ::size_t) -> ::ssize_t;
591651
}
592652

593653
cfg_if! {

0 commit comments

Comments
 (0)