Skip to content

Commit 28bcafa

Browse files
committed
Auto merge of #31668 - cuviper:lfs, r=alexcrichton
This follows the pattern already used for stat functions from #31551. Now `ftruncate`, `lseek`, and `readdir_r` use their explicit 64-bit variants for LFS support, using wider `off_t` and `dirent` types. This also updates to `open64`, which uses no different types but implies the `O_LARGEFILE` flag. Non-Linux platforms just map their normal functions to the 64-bit names. r? @alexcrichton
2 parents 29e8ac5 + c84ab39 commit 28bcafa

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/libstd/sys/unix/fs.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use os::unix::prelude::*;
1515
use ffi::{CString, CStr, OsString, OsStr};
1616
use fmt;
1717
use io::{self, Error, ErrorKind, SeekFrom};
18-
use libc::{self, dirent, c_int, off_t, mode_t};
18+
use libc::{self, c_int, mode_t};
1919
use mem;
2020
use path::{Path, PathBuf};
2121
use ptr;
@@ -26,9 +26,12 @@ use sys::{cvt, cvt_r};
2626
use sys_common::{AsInner, FromInner};
2727

2828
#[cfg(target_os = "linux")]
29-
use libc::{stat64, fstat64, lstat64};
29+
use libc::{stat64, fstat64, lstat64, off64_t, ftruncate64, lseek64, dirent64, readdir64_r, open64};
3030
#[cfg(not(target_os = "linux"))]
31-
use libc::{stat as stat64, fstat as fstat64, lstat as lstat64};
31+
use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, off_t as off64_t,
32+
ftruncate as ftruncate64, lseek as lseek64, dirent as dirent64, open as open64};
33+
#[cfg(not(any(target_os = "linux", target_os = "solaris")))]
34+
use libc::{readdir_r as readdir64_r};
3235

3336
pub struct File(FileDesc);
3437

@@ -48,7 +51,7 @@ unsafe impl Send for Dir {}
4851
unsafe impl Sync for Dir {}
4952

5053
pub struct DirEntry {
51-
entry: dirent,
54+
entry: dirent64,
5255
root: Arc<PathBuf>,
5356
// We need to store an owned copy of the directory name
5457
// on Solaris because a) it uses a zero-length array to
@@ -223,7 +226,7 @@ impl Iterator for ReadDir {
223226
};
224227
let mut entry_ptr = ptr::null_mut();
225228
loop {
226-
if libc::readdir_r(self.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 {
229+
if readdir64_r(self.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 {
227230
return Some(Err(Error::last_os_error()))
228231
}
229232
if entry_ptr.is_null() {
@@ -394,7 +397,7 @@ impl File {
394397
try!(opts.get_creation_mode()) |
395398
(opts.custom_flags as c_int & !libc::O_ACCMODE);
396399
let fd = try!(cvt_r(|| unsafe {
397-
libc::open(path.as_ptr(), flags, opts.mode as c_int)
400+
open64(path.as_ptr(), flags, opts.mode as c_int)
398401
}));
399402
let fd = FileDesc::new(fd);
400403

@@ -443,7 +446,7 @@ impl File {
443446

444447
pub fn truncate(&self, size: u64) -> io::Result<()> {
445448
try!(cvt_r(|| unsafe {
446-
libc::ftruncate(self.0.raw(), size as libc::off_t)
449+
ftruncate64(self.0.raw(), size as off64_t)
447450
}));
448451
Ok(())
449452
}
@@ -460,11 +463,11 @@ impl File {
460463

461464
pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> {
462465
let (whence, pos) = match pos {
463-
SeekFrom::Start(off) => (libc::SEEK_SET, off as off_t),
464-
SeekFrom::End(off) => (libc::SEEK_END, off as off_t),
465-
SeekFrom::Current(off) => (libc::SEEK_CUR, off as off_t),
466+
SeekFrom::Start(off) => (libc::SEEK_SET, off as off64_t),
467+
SeekFrom::End(off) => (libc::SEEK_END, off as off64_t),
468+
SeekFrom::Current(off) => (libc::SEEK_CUR, off as off64_t),
466469
};
467-
let n = try!(cvt(unsafe { libc::lseek(self.0.raw(), pos, whence) }));
470+
let n = try!(cvt(unsafe { lseek64(self.0.raw(), pos, whence) }));
468471
Ok(n as u64)
469472
}
470473

0 commit comments

Comments
 (0)