about summary refs log tree commit diff
path: root/src/libnative
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-05-29 06:11:39 -0700
committerbors <bors@rust-lang.org>2014-05-29 06:11:39 -0700
commitbee4e6adac17f87b1cdc26ab69f8c0f5d82575a3 (patch)
tree9b0ef364d66b855094a3a390f7d38095c042f9a9 /src/libnative
parentff2bf58e9e0c1e7b154b88fc7ba8c52584e9f768 (diff)
parent2e8bc9924c096cb8f889d3f46ecce7ebe622b964 (diff)
downloadrust-bee4e6adac17f87b1cdc26ab69f8c0f5d82575a3.tar.gz
rust-bee4e6adac17f87b1cdc26ab69f8c0f5d82575a3.zip
auto merge of #14487 : arielb1/rust/fix-13933, r=alexcrichton
Fix issue #13933 in a few files. A more complete fix would require core::raw::MutSlice.
Diffstat (limited to 'src/libnative')
-rw-r--r--src/libnative/io/file_win32.rs40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/libnative/io/file_win32.rs b/src/libnative/io/file_win32.rs
index c9a48db6920..4f1f3b3ca26 100644
--- a/src/libnative/io/file_win32.rs
+++ b/src/libnative/io/file_win32.rs
@@ -90,6 +90,25 @@ impl FileDesc {
     pub fn handle(&self) -> libc::HANDLE {
         unsafe { libc::get_osfhandle(self.fd()) as libc::HANDLE }
     }
+
+    // A version of seek that takes &self so that tell can call it
+    //   - the private seek should of course take &mut self.
+    fn seek_common(&self, pos: i64, style: io::SeekStyle) -> Result<u64, IoError> {
+        let whence = match style {
+            io::SeekSet => libc::FILE_BEGIN,
+            io::SeekEnd => libc::FILE_END,
+            io::SeekCur => libc::FILE_CURRENT,
+        };
+        unsafe {
+            let mut newpos = 0;
+            match libc::SetFilePointerEx(self.handle(), pos, &mut newpos,
+                                         whence) {
+                0 => Err(super::last_error()),
+                _ => Ok(newpos as u64),
+            }
+        }
+    }
+
 }
 
 impl io::Reader for FileDesc {
@@ -151,26 +170,13 @@ impl rtio::RtioFileStream for FileDesc {
         }
         Ok(())
     }
+
     fn seek(&mut self, pos: i64, style: io::SeekStyle) -> Result<u64, IoError> {
-        let whence = match style {
-            io::SeekSet => libc::FILE_BEGIN,
-            io::SeekEnd => libc::FILE_END,
-            io::SeekCur => libc::FILE_CURRENT,
-        };
-        unsafe {
-            let mut newpos = 0;
-            match libc::SetFilePointerEx(self.handle(), pos, &mut newpos,
-                                         whence) {
-                0 => Err(super::last_error()),
-                _ => Ok(newpos as u64),
-            }
-        }
+        self.seek_common(pos, style)
     }
+
     fn tell(&self) -> Result<u64, IoError> {
-        // This transmute is fine because our seek implementation doesn't
-        // actually use the mutable self at all.
-        // FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes
-        unsafe { mem::transmute::<&_, &mut FileDesc>(self).seek(0, io::SeekCur) }
+        self.seek_common(0, io::SeekCur)
     }
 
     fn fsync(&mut self) -> Result<(), IoError> {