Skip to content

Commit 14bf9de

Browse files
committed
Merge pull request rust-lang#23 from alexcrichton/lfs-support
Use bindings for -D_FILE_OFFSET_BITS=64
2 parents 312b5bf + 7482522 commit 14bf9de

File tree

11 files changed

+221
-54
lines changed

11 files changed

+221
-54
lines changed

libc-test/build.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fn main() {
152152
match field {
153153
// Our stat *_nsec fields normally don't actually exist but are part
154154
// of a timeval struct
155-
s if s.ends_with("_nsec") && struct_ == "stat" => {
155+
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
156156
if target2.contains("apple") {
157157
s.replace("_nsec", "spec.tv_nsec")
158158
} else if target2.contains("android") {
@@ -203,6 +203,12 @@ fn main() {
203203
// types on musl are defined a little differently
204204
n if musl && n.contains("__SIZEOF_PTHREAD") => true,
205205

206+
// Skip constants not defined in MUSL but just passed down to the
207+
// kernel regardless
208+
"RLIMIT_NLIMITS" |
209+
"TCP_COOKIE_TRANSACTIONS" |
210+
"RLIMIT_RTTIME" if musl => true,
211+
206212
_ => false,
207213
}
208214
});
@@ -215,8 +221,8 @@ fn main() {
215221
"execvp" |
216222
"execvpe" => true,
217223

218-
"getrlimit" | // non-int in 1st arg
219-
"setrlimit" | // non-int in 1st arg
224+
"getrlimit" | "getrlimit64" | // non-int in 1st arg
225+
"setrlimit" | "setrlimit64" | // non-int in 1st arg
220226
"strerror_r" if linux => true, // actually xpg-something-or-other
221227

222228
// typed 2nd arg on linux and android

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub type uintptr_t = usize;
100100
pub type ssize_t = isize;
101101

102102
pub enum FILE {}
103-
pub enum fpos_t {}
103+
pub enum fpos_t {} // TODO: fill this out with a struct
104104

105105
extern {
106106
pub fn isalnum(c: c_int) -> c_int;

src/unix/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ extern {
174174
pub fn opendir(dirname: *const c_char) -> *mut ::DIR;
175175
#[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")]
176176
pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent,
177-
result: *mut *mut ::dirent) -> ::c_int;
177+
result: *mut *mut ::dirent) -> ::c_int;
178178
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
179179
link_name = "closedir$UNIX2003")]
180180
pub fn closedir(dirp: *mut ::DIR) -> ::c_int;
@@ -220,8 +220,7 @@ extern {
220220
pub fn getuid() -> uid_t;
221221
pub fn isatty(fd: ::c_int) -> ::c_int;
222222
pub fn link(src: *const c_char, dst: *const c_char) -> ::c_int;
223-
pub fn lseek(fd: ::c_int, offset: off_t, whence: ::c_int)
224-
-> off_t;
223+
pub fn lseek(fd: ::c_int, offset: off_t, whence: ::c_int) -> off_t;
225224
pub fn pathconf(path: *const c_char, name: ::c_int) -> c_long;
226225
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
227226
link_name = "pause$UNIX2003")]
@@ -526,6 +525,10 @@ extern {
526525
errorfds: *mut fd_set,
527526
timeout: *const timespec,
528527
sigmask: *const sigset_t) -> ::c_int;
528+
pub fn fseeko(stream: *mut ::FILE,
529+
offset: ::off_t,
530+
whence: ::c_int) -> ::c_int;
531+
pub fn ftello(stream: *mut ::FILE) -> ::off_t;
529532
}
530533

531534
cfg_if! {

src/unix/notbsd/linux/mips.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub type nlink_t = u32;
1414
s! {
1515
pub struct stat {
1616
pub st_dev: ::c_ulong,
17-
pub st_pad1: [::c_long; 3],
17+
st_pad1: [::c_long; 3],
1818
pub st_ino: ::ino_t,
1919
pub st_mode: ::mode_t,
2020
pub st_nlink: ::nlink_t,
@@ -23,7 +23,7 @@ s! {
2323
pub st_rdev: ::c_ulong,
2424
pub st_pad2: [::c_long; 2],
2525
pub st_size: ::off_t,
26-
pub st_pad3: ::c_long,
26+
st_pad3: ::c_long,
2727
pub st_atime: ::time_t,
2828
pub st_atime_nsec: ::c_long,
2929
pub st_mtime: ::time_t,
@@ -32,7 +32,30 @@ s! {
3232
pub st_ctime_nsec: ::c_long,
3333
pub st_blksize: ::blksize_t,
3434
pub st_blocks: ::blkcnt_t,
35-
pub st_pad5: [::c_long; 14],
35+
st_pad5: [::c_long; 14],
36+
}
37+
38+
pub struct stat64 {
39+
pub st_dev: ::c_ulong,
40+
st_pad1: [::c_long; 3],
41+
pub st_ino: ::ino64_t,
42+
pub st_mode: ::mode_t,
43+
pub st_nlink: ::nlink_t,
44+
pub st_uid: ::uid_t,
45+
pub st_gid: ::gid_t,
46+
pub st_rdev: ::c_ulong,
47+
st_pad2: [::c_long; 2],
48+
pub st_size: ::off64_t,
49+
pub st_atime: ::time_t,
50+
pub st_atime_nsec: ::c_long,
51+
pub st_mtime: ::time_t,
52+
pub st_mtime_nsec: ::c_long,
53+
pub st_ctime: ::time_t,
54+
pub st_ctime_nsec: ::c_long,
55+
pub st_blksize: ::blksize_t,
56+
st_pad3: ::c_long,
57+
pub st_blocks: ::blkcnt64_t,
58+
st_pad5: [::c_long; 14],
3659
}
3760

3861
pub struct pthread_attr_t {

src/unix/notbsd/linux/mod.rs

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ pub type dev_t = u64;
55
pub type socklen_t = u32;
66
pub type pthread_t = c_ulong;
77
pub type mode_t = u32;
8+
pub type ino64_t = u64;
9+
pub type off64_t = i64;
10+
pub type blkcnt64_t = i64;
11+
pub type rlim64_t = u64;
12+
13+
pub enum fpos64_t {} // TODO: fill this out with a struct
814

915
s! {
1016
pub struct dirent {
@@ -15,6 +21,19 @@ s! {
1521
pub d_name: [::c_char; 256],
1622
}
1723

24+
pub struct dirent64 {
25+
pub d_ino: ::ino64_t,
26+
pub d_off: ::off64_t,
27+
pub d_reclen: ::c_ushort,
28+
pub d_type: ::c_uchar,
29+
pub d_name: [::c_char; 256],
30+
}
31+
32+
pub struct rlimit64 {
33+
pub rlim_cur: rlim64_t,
34+
pub rlim_max: rlim64_t,
35+
}
36+
1837
pub struct glob_t {
1938
pub gl_pathc: ::size_t,
2039
pub gl_pathv: *mut *mut c_char,
@@ -226,13 +245,47 @@ extern {
226245
-> ::c_int;
227246
pub fn __errno_location() -> *mut ::c_int;
228247

248+
pub fn fopen64(filename: *const c_char,
249+
mode: *const c_char) -> *mut ::FILE;
250+
pub fn freopen64(filename: *const c_char, mode: *const c_char,
251+
file: *mut ::FILE) -> *mut ::FILE;
252+
pub fn tmpfile64() -> *mut ::FILE;
253+
pub fn fgetpos64(stream: *mut ::FILE, ptr: *mut fpos64_t) -> ::c_int;
254+
pub fn fsetpos64(stream: *mut ::FILE, ptr: *const fpos64_t) -> ::c_int;
255+
pub fn fstat64(fildes: ::c_int, buf: *mut stat64) -> ::c_int;
256+
pub fn stat64(path: *const c_char, buf: *mut stat64) -> ::c_int;
257+
pub fn open64(path: *const c_char, oflag: ::c_int, ...) -> ::c_int;
258+
pub fn creat64(path: *const c_char, mode: mode_t) -> ::c_int;
259+
pub fn lseek64(fd: ::c_int, offset: off64_t, whence: ::c_int) -> off64_t;
260+
pub fn pread64(fd: ::c_int, buf: *mut ::c_void, count: ::size_t,
261+
offset: off64_t) -> ::ssize_t;
262+
pub fn pwrite64(fd: ::c_int, buf: *const ::c_void, count: ::size_t,
263+
offset: off64_t) -> ::ssize_t;
264+
pub fn mmap64(addr: *mut ::c_void,
265+
len: ::size_t,
266+
prot: ::c_int,
267+
flags: ::c_int,
268+
fd: ::c_int,
269+
offset: off64_t)
270+
-> *mut ::c_void;
271+
pub fn lstat64(path: *const c_char, buf: *mut stat64) -> ::c_int;
272+
pub fn ftruncate64(fd: ::c_int, length: off64_t) -> ::c_int;
273+
pub fn readdir64_r(dirp: *mut ::DIR, entry: *mut ::dirent64,
274+
result: *mut *mut ::dirent64) -> ::c_int;
275+
276+
pub fn getrlimit64(resource: ::c_int, rlim: *mut rlimit64) -> ::c_int;
277+
pub fn setrlimit64(resource: ::c_int, rlim: *const rlimit64) -> ::c_int;
278+
pub fn fseeko64(stream: *mut ::FILE,
279+
offset: ::off64_t,
280+
whence: ::c_int) -> ::c_int;
281+
pub fn ftello64(stream: *mut ::FILE) -> ::off64_t;
229282
}
230283

231284
cfg_if! {
232285
if #[cfg(any(target_env = "musl"))] {
233286
pub const PTHREAD_STACK_MIN: ::size_t = 2048;
234287
} else if #[cfg(any(target_arch = "arm", target_arch = "x86",
235-
target_arch = "x86_64"))] {
288+
target_arch = "x86_64"))] {
236289
pub const PTHREAD_STACK_MIN: ::size_t = 16384;
237290
} else {
238291
pub const PTHREAD_STACK_MIN: ::size_t = 131072;
@@ -241,38 +294,11 @@ cfg_if! {
241294

242295
cfg_if! {
243296
if #[cfg(target_env = "musl")] {
244-
pub const BUFSIZ: ::c_uint = 1024;
245-
pub const TMP_MAX: ::c_uint = 10000;
246-
pub const FOPEN_MAX: ::c_uint = 1000;
247-
pub const POSIX_MADV_DONTNEED: ::c_int = 0;
248-
pub const O_ACCMODE: ::c_int = 0o10000003;
249-
pub const RUSAGE_CHILDREN: ::c_int = 1;
250-
251-
extern {
252-
pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;
253-
}
297+
mod musl;
298+
pub use self::musl::*;
254299
} else {
255-
pub const BUFSIZ: ::c_uint = 8192;
256-
pub const TMP_MAX: ::c_uint = 238328;
257-
pub const FOPEN_MAX: ::c_uint = 16;
258-
pub const POSIX_MADV_DONTNEED: ::c_int = 4;
259-
pub const _SC_2_C_VERSION: ::c_int = 96;
260-
pub const RUSAGE_THREAD: ::c_int = 1;
261-
pub const O_ACCMODE: ::c_int = 3;
262-
pub const RUSAGE_CHILDREN: ::c_int = -1;
263-
264-
extern {
265-
pub fn sysctl(name: *mut ::c_int,
266-
namelen: ::c_int,
267-
oldp: *mut ::c_void,
268-
oldlenp: *mut ::size_t,
269-
newp: *mut ::c_void,
270-
newlen: ::size_t)
271-
-> ::c_int;
272-
pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int;
273-
pub fn backtrace(buf: *mut *mut ::c_void,
274-
sz: ::c_int) -> ::c_int;
275-
}
300+
mod notmusl;
301+
pub use self::notmusl::*;
276302
}
277303
}
278304

src/unix/notbsd/linux/musl.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pub const BUFSIZ: ::c_uint = 1024;
2+
pub const TMP_MAX: ::c_uint = 10000;
3+
pub const FOPEN_MAX: ::c_uint = 1000;
4+
pub const POSIX_MADV_DONTNEED: ::c_int = 0;
5+
pub const O_ACCMODE: ::c_int = 0o10000003;
6+
pub const RUSAGE_CHILDREN: ::c_int = 1;
7+
8+
extern {
9+
pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;
10+
}

src/unix/notbsd/linux/notmips/b32/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ s! {
4040
__unused5: ::c_long,
4141
}
4242

43+
pub struct stat64 {
44+
pub st_dev: ::dev_t,
45+
__pad1: ::c_uint,
46+
__st_ino: ::ino_t,
47+
pub st_mode: ::mode_t,
48+
pub st_nlink: ::nlink_t,
49+
pub st_uid: ::uid_t,
50+
pub st_gid: ::gid_t,
51+
pub st_rdev: ::dev_t,
52+
__pad2: ::c_uint,
53+
pub st_size: ::off64_t,
54+
pub st_blksize: ::blksize_t,
55+
pub st_blocks: ::blkcnt64_t,
56+
pub st_atime: ::time_t,
57+
pub st_atime_nsec: ::c_long,
58+
pub st_mtime: ::time_t,
59+
pub st_mtime_nsec: ::c_long,
60+
pub st_ctime: ::time_t,
61+
pub st_ctime_nsec: ::c_long,
62+
pub st_ino: ::ino64_t,
63+
}
64+
4365
pub struct pthread_attr_t {
4466
__size: [u32; 9]
4567
}

src/unix/notbsd/linux/notmips/b64/aarch64.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ s! {
3131
__unused: [::c_int; 2],
3232
}
3333

34+
pub struct stat64 {
35+
pub st_dev: ::dev_t,
36+
pub st_ino: ::ino_t,
37+
pub st_mode: ::mode_t,
38+
pub st_nlink: ::nlink_t,
39+
pub st_uid: ::uid_t,
40+
pub st_gid: ::gid_t,
41+
pub st_rdev: ::dev_t,
42+
__pad1: ::dev_t,
43+
pub st_size: ::off64_t,
44+
pub st_blksize: ::blksize_t,
45+
__pad2: ::c_int,
46+
pub st_blocks: ::blkcnt64_t,
47+
pub st_atime: ::time_t,
48+
pub st_atime_nsec: ::c_long,
49+
pub st_mtime: ::time_t,
50+
pub st_mtime_nsec: ::c_long,
51+
pub st_ctime: ::time_t,
52+
pub st_ctime_nsec: ::c_long,
53+
__unused: [::c_int; 2],
54+
}
55+
3456
pub struct pthread_attr_t {
3557
__size: [u64; 8]
3658
}

src/unix/notbsd/linux/notmips/b64/x86_64.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,27 @@ s! {
3030
__unused: [::c_long; 3],
3131
}
3232

33+
pub struct stat64 {
34+
pub st_dev: ::dev_t,
35+
pub st_ino: ::ino64_t,
36+
pub st_nlink: ::nlink_t,
37+
pub st_mode: ::mode_t,
38+
pub st_uid: ::uid_t,
39+
pub st_gid: ::gid_t,
40+
__pad0: ::c_int,
41+
pub st_rdev: ::dev_t,
42+
pub st_size: ::off_t,
43+
pub st_blksize: ::blksize_t,
44+
pub st_blocks: ::blkcnt64_t,
45+
pub st_atime: ::time_t,
46+
pub st_atime_nsec: ::c_long,
47+
pub st_mtime: ::time_t,
48+
pub st_mtime_nsec: ::c_long,
49+
pub st_ctime: ::time_t,
50+
pub st_ctime_nsec: ::c_long,
51+
__reserved: [::c_long; 3],
52+
}
53+
3354
pub struct pthread_attr_t {
3455
__size: [u64; 7]
3556
}

src/unix/notbsd/linux/notmips/mod.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pub const RLIMIT_AS: ::c_int = 9;
2727
pub const RLIMIT_NPROC: ::c_int = 6;
2828
pub const RLIMIT_MEMLOCK: ::c_int = 8;
2929
pub const RLIM_INFINITY: ::rlim_t = !0;
30+
pub const RLIMIT_RTTIME: ::c_int = 15;
31+
pub const RLIMIT_NLIMITS: ::c_int = 16;
3032

3133
pub const O_APPEND: ::c_int = 1024;
3234
pub const O_CREAT: ::c_int = 64;
@@ -148,12 +150,14 @@ pub const SO_RCVBUF: ::c_int = 8;
148150
pub const SO_KEEPALIVE: ::c_int = 9;
149151
pub const SO_OOBINLINE: ::c_int = 10;
150152
pub const SO_LINGER: ::c_int = 13;
153+
pub const SO_REUSEPORT: ::c_int = 15;
151154
pub const SO_RCVLOWAT: ::c_int = 18;
152155
pub const SO_SNDLOWAT: ::c_int = 19;
153156
pub const SO_RCVTIMEO: ::c_int = 20;
154157
pub const SO_SNDTIMEO: ::c_int = 21;
155158
pub const SO_ACCEPTCONN: ::c_int = 30;
156159

160+
pub const TCP_COOKIE_TRANSACTIONS: ::c_int = 15;
157161
pub const TCP_THIN_LINEAR_TIMEOUTS: ::c_int = 16;
158162
pub const TCP_THIN_DUPACK: ::c_int = 17;
159163
pub const TCP_USER_TIMEOUT: ::c_int = 18;
@@ -164,8 +168,6 @@ pub const TCP_REPAIR_OPTIONS: ::c_int = 22;
164168
pub const TCP_FASTOPEN: ::c_int = 23;
165169
pub const TCP_TIMESTAMP: ::c_int = 24;
166170

167-
pub const SO_REUSEPORT: ::c_int = 15;
168-
169171
pub const FIOCLEX: ::c_ulong = 0x5451;
170172
pub const FIONBIO: ::c_ulong = 0x5421;
171173

@@ -177,16 +179,6 @@ pub const SIGCHLD: ::c_int = 17;
177179
pub const SIGBUS: ::c_int = 7;
178180
pub const SIG_SETMASK: ::c_int = 2;
179181

180-
cfg_if! {
181-
if #[cfg(target_env = "musl")] {
182-
pub const RLIMIT_NLIMITS: ::c_int = 15;
183-
} else {
184-
pub const RLIMIT_NLIMITS: ::c_int = 16;
185-
pub const RLIMIT_RTTIME: ::c_int = 15;
186-
pub const TCP_COOKIE_TRANSACTIONS: ::c_int = 15;
187-
}
188-
}
189-
190182
cfg_if! {
191183
if #[cfg(any(target_arch = "x86", target_arch = "arm"))] {
192184
mod b32;

0 commit comments

Comments
 (0)