@@ -27,7 +27,7 @@ use sys_common::{AsInner, FromInner};
2727#[ cfg( any( target_os = "linux" , target_os = "emscripten" ) ) ]
2828use libc:: { stat64, fstat64, lstat64, off64_t, ftruncate64, lseek64, dirent64, readdir64_r, open64} ;
2929#[ cfg( target_os = "android" ) ]
30- use libc:: { stat as stat64, fstat as fstat64, lstat as lstat64, off64_t , lseek64,
30+ use libc:: { stat as stat64, fstat as fstat64, lstat as lstat64, lseek64,
3131 dirent as dirent64, open as open64} ;
3232#[ cfg( not( any( target_os = "linux" ,
3333 target_os = "emscripten" ,
@@ -485,9 +485,11 @@ impl File {
485485
486486 pub fn seek ( & self , pos : SeekFrom ) -> io:: Result < u64 > {
487487 let ( whence, pos) = match pos {
488- SeekFrom :: Start ( off) => ( libc:: SEEK_SET , off as off64_t ) ,
489- SeekFrom :: End ( off) => ( libc:: SEEK_END , off as off64_t ) ,
490- SeekFrom :: Current ( off) => ( libc:: SEEK_CUR , off as off64_t ) ,
488+ // Casting to `i64` is fine, too large values will end up as
489+ // negative which will cause an error in `lseek64`.
490+ SeekFrom :: Start ( off) => ( libc:: SEEK_SET , off as i64 ) ,
491+ SeekFrom :: End ( off) => ( libc:: SEEK_END , off) ,
492+ SeekFrom :: Current ( off) => ( libc:: SEEK_CUR , off) ,
491493 } ;
492494 let n = cvt ( unsafe { lseek64 ( self . 0 . raw ( ) , pos, whence) } ) ?;
493495 Ok ( n as u64 )
0 commit comments