about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-08-06 05:02:16 -0700
committerGitHub <noreply@github.com>2016-08-06 05:02:16 -0700
commit444ff9fbfb1f2a8e6645f67684f8a9ad99b343d3 (patch)
treedad9595deade059b82952d7c38ccef3140686537 /src/libstd/sys
parentecdd51b7bb7fd993acd2ff5dbd72209244b1e4aa (diff)
parent67f082287d49320af9042678b861437cd8d0224c (diff)
downloadrust-444ff9fbfb1f2a8e6645f67684f8a9ad99b343d3.tar.gz
rust-444ff9fbfb1f2a8e6645f67684f8a9ad99b343d3.zip
Auto merge of #35407 - eddyb:rollup, r=eddyb
Rollup of 21 pull requests

- Successful merges: #33951, #34916, #35287, #35288, #35351, #35353, #35356, #35362, #35363, #35364, #35366, #35368, #35370, #35372, #35373, #35374, #35375, #35376, #35380, #35393, #35394
- Failed merges: #35331, #35395
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/unix/fs.rs10
-rw-r--r--src/libstd/sys/windows/fs.rs2
2 files changed, 8 insertions, 4 deletions
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs
index b315e676263..3b132744f70 100644
--- a/src/libstd/sys/unix/fs.rs
+++ b/src/libstd/sys/unix/fs.rs
@@ -27,7 +27,7 @@ use sys_common::{AsInner, FromInner};
 #[cfg(any(target_os = "linux", target_os = "emscripten"))]
 use libc::{stat64, fstat64, lstat64, off64_t, ftruncate64, lseek64, dirent64, readdir64_r, open64};
 #[cfg(target_os = "android")]
-use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, off64_t, lseek64,
+use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, lseek64,
            dirent as dirent64, open as open64};
 #[cfg(not(any(target_os = "linux",
               target_os = "emscripten",
@@ -485,9 +485,11 @@ impl File {
 
     pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> {
         let (whence, pos) = match pos {
-            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),
+            // Casting to `i64` is fine, too large values will end up as
+            // negative which will cause an error in `lseek64`.
+            SeekFrom::Start(off) => (libc::SEEK_SET, off as i64),
+            SeekFrom::End(off) => (libc::SEEK_END, off),
+            SeekFrom::Current(off) => (libc::SEEK_CUR, off),
         };
         let n = cvt(unsafe { lseek64(self.0.raw(), pos, whence) })?;
         Ok(n as u64)
diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs
index 2683e57256d..4e6cef9a28d 100644
--- a/src/libstd/sys/windows/fs.rs
+++ b/src/libstd/sys/windows/fs.rs
@@ -324,6 +324,8 @@ impl File {
 
     pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> {
         let (whence, pos) = match pos {
+            // Casting to `i64` is fine, `SetFilePointerEx` reinterprets this
+            // integer as `u64`.
             SeekFrom::Start(n) => (c::FILE_BEGIN, n as i64),
             SeekFrom::End(n) => (c::FILE_END, n),
             SeekFrom::Current(n) => (c::FILE_CURRENT, n),