From 1ea38f8928a017ce544faf9d025853211dbce49c Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Sun, 14 Feb 2016 16:09:57 -0800 Subject: [PATCH 1/4] std: use LFS ftruncate64 on Linux --- src/libstd/sys/unix/fs.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 14f30a62576..55667aced5e 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -26,9 +26,10 @@ use sys::{cvt, cvt_r}; use sys_common::{AsInner, FromInner}; #[cfg(target_os = "linux")] -use libc::{stat64, fstat64, lstat64}; +use libc::{stat64, fstat64, lstat64, off64_t, ftruncate64}; #[cfg(not(target_os = "linux"))] -use libc::{stat as stat64, fstat as fstat64, lstat as lstat64}; +use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, off_t as off64_t, + ftruncate as ftruncate64}; pub struct File(FileDesc); @@ -443,7 +444,7 @@ impl File { pub fn truncate(&self, size: u64) -> io::Result<()> { try!(cvt_r(|| unsafe { - libc::ftruncate(self.0.raw(), size as libc::off_t) + ftruncate64(self.0.raw(), size as off64_t) })); Ok(()) } From dcdfed49d7414a44bb3cfe73cf62ad2881055230 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Sun, 14 Feb 2016 16:15:39 -0800 Subject: [PATCH 2/4] std: use LFS lseek64 on Linux --- src/libstd/sys/unix/fs.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 55667aced5e..ab8b700e193 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -15,7 +15,7 @@ use os::unix::prelude::*; use ffi::{CString, CStr, OsString, OsStr}; use fmt; use io::{self, Error, ErrorKind, SeekFrom}; -use libc::{self, dirent, c_int, off_t, mode_t}; +use libc::{self, dirent, c_int, mode_t}; use mem; use path::{Path, PathBuf}; use ptr; @@ -26,10 +26,10 @@ use sys::{cvt, cvt_r}; use sys_common::{AsInner, FromInner}; #[cfg(target_os = "linux")] -use libc::{stat64, fstat64, lstat64, off64_t, ftruncate64}; +use libc::{stat64, fstat64, lstat64, off64_t, ftruncate64, lseek64}; #[cfg(not(target_os = "linux"))] use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, off_t as off64_t, - ftruncate as ftruncate64}; + ftruncate as ftruncate64, lseek as lseek64}; pub struct File(FileDesc); @@ -461,11 +461,11 @@ impl File { pub fn seek(&self, pos: SeekFrom) -> io::Result { let (whence, pos) = match pos { - SeekFrom::Start(off) => (libc::SEEK_SET, off as off_t), - SeekFrom::End(off) => (libc::SEEK_END, off as off_t), - SeekFrom::Current(off) => (libc::SEEK_CUR, off as off_t), + SeekFrom::Start(off) => (libc::SEEK_SET, off as off64_t), + SeekFrom::End(off) => (libc::SEEK_END, off as off64_t), + SeekFrom::Current(off) => (libc::SEEK_CUR, off as off64_t), }; - let n = try!(cvt(unsafe { libc::lseek(self.0.raw(), pos, whence) })); + let n = try!(cvt(unsafe { lseek64(self.0.raw(), pos, whence) })); Ok(n as u64) } From 8f2d7d956ce54e77e98472f4d80e24fdf662560e Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Sun, 14 Feb 2016 16:24:02 -0800 Subject: [PATCH 3/4] std: use LFS readdir64_r on Linux --- src/libstd/sys/unix/fs.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index ab8b700e193..a2ff0d8e1d1 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -15,7 +15,7 @@ use os::unix::prelude::*; use ffi::{CString, CStr, OsString, OsStr}; use fmt; use io::{self, Error, ErrorKind, SeekFrom}; -use libc::{self, dirent, c_int, mode_t}; +use libc::{self, c_int, mode_t}; use mem; use path::{Path, PathBuf}; use ptr; @@ -26,10 +26,12 @@ use sys::{cvt, cvt_r}; use sys_common::{AsInner, FromInner}; #[cfg(target_os = "linux")] -use libc::{stat64, fstat64, lstat64, off64_t, ftruncate64, lseek64}; +use libc::{stat64, fstat64, lstat64, off64_t, ftruncate64, lseek64, dirent64, readdir64_r}; #[cfg(not(target_os = "linux"))] use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, off_t as off64_t, - ftruncate as ftruncate64, lseek as lseek64}; + ftruncate as ftruncate64, lseek as lseek64, dirent as dirent64}; +#[cfg(not(any(target_os = "linux", target_os = "solaris")))] +use libc::{readdir_r as readdir64_r}; pub struct File(FileDesc); @@ -49,7 +51,7 @@ unsafe impl Send for Dir {} unsafe impl Sync for Dir {} pub struct DirEntry { - entry: dirent, + entry: dirent64, root: Arc, // We need to store an owned copy of the directory name // on Solaris because a) it uses a zero-length array to @@ -224,7 +226,7 @@ impl Iterator for ReadDir { }; let mut entry_ptr = ptr::null_mut(); loop { - if libc::readdir_r(self.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 { + if readdir64_r(self.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 { return Some(Err(Error::last_os_error())) } if entry_ptr.is_null() { From c84ab396350b81f07a87071c6b305cc513872a3e Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Sun, 14 Feb 2016 16:27:18 -0800 Subject: [PATCH 4/4] std: use LFS open64 on Linux --- src/libstd/sys/unix/fs.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index a2ff0d8e1d1..e8e0a604e55 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -26,10 +26,10 @@ use sys::{cvt, cvt_r}; use sys_common::{AsInner, FromInner}; #[cfg(target_os = "linux")] -use libc::{stat64, fstat64, lstat64, off64_t, ftruncate64, lseek64, dirent64, readdir64_r}; +use libc::{stat64, fstat64, lstat64, off64_t, ftruncate64, lseek64, dirent64, readdir64_r, open64}; #[cfg(not(target_os = "linux"))] use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, off_t as off64_t, - ftruncate as ftruncate64, lseek as lseek64, dirent as dirent64}; + ftruncate as ftruncate64, lseek as lseek64, dirent as dirent64, open as open64}; #[cfg(not(any(target_os = "linux", target_os = "solaris")))] use libc::{readdir_r as readdir64_r}; @@ -397,7 +397,7 @@ impl File { try!(opts.get_creation_mode()) | (opts.custom_flags as c_int & !libc::O_ACCMODE); let fd = try!(cvt_r(|| unsafe { - libc::open(path.as_ptr(), flags, opts.mode as c_int) + open64(path.as_ptr(), flags, opts.mode as c_int) })); let fd = FileDesc::new(fd);