@@ -27,7 +27,7 @@ use sys_common::{AsInner, FromInner};
27
27
#[ cfg( any( target_os = "linux" , target_os = "emscripten" ) ) ]
28
28
use libc:: { stat64, fstat64, lstat64, off64_t, ftruncate64, lseek64, dirent64, readdir64_r, open64} ;
29
29
#[ 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,
31
31
dirent as dirent64, open as open64} ;
32
32
#[ cfg( not( any( target_os = "linux" ,
33
33
target_os = "emscripten" ,
@@ -485,9 +485,11 @@ impl File {
485
485
486
486
pub fn seek ( & self , pos : SeekFrom ) -> io:: Result < u64 > {
487
487
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) ,
491
493
} ;
492
494
let n = cvt ( unsafe { lseek64 ( self . 0 . raw ( ) , pos, whence) } ) ?;
493
495
Ok ( n as u64 )
0 commit comments