@@ -18,27 +18,6 @@ use sys::cvt;
1818use sys_common:: AsInner ;
1919use sys_common:: io:: read_to_end_uninitialized;
2020
21- #[ cfg( target_os = "android" ) ]
22- use super :: android:: { cvt_pread64, cvt_pwrite64} ;
23- #[ cfg( any( target_os = "linux" , target_os = "emscripten" ) ) ]
24- use libc:: { pread64, pwrite64, off64_t, ssize_t} ;
25- #[ cfg( not( any( target_os = "linux" , target_os = "emscripten" , target_os = "android" ) ) ) ]
26- use libc:: { pread as pread64, pwrite as pwrite64, off_t as off64_t, ssize_t} ;
27-
28- #[ cfg( not( target_os = "android" ) ) ]
29- unsafe fn cvt_pread64 ( fd : c_int , buf : * mut c_void , count : size_t , offset : off64_t )
30- -> io:: Result < ssize_t >
31- {
32- cvt ( pread64 ( fd, buf, count, offset) )
33- }
34-
35- #[ cfg( not( target_os = "android" ) ) ]
36- unsafe fn cvt_pwrite64 ( fd : c_int , buf : * const c_void , count : size_t , offset : off64_t )
37- -> io:: Result < ssize_t >
38- {
39- cvt ( pwrite64 ( fd, buf, count, offset) )
40- }
41-
4221pub struct FileDesc {
4322 fd : c_int ,
4423}
@@ -72,11 +51,25 @@ impl FileDesc {
7251 }
7352
7453 pub fn read_at ( & self , buf : & mut [ u8 ] , offset : u64 ) -> io:: Result < usize > {
54+ #[ cfg( target_os = "android" ) ]
55+ use super :: android:: cvt_pread64;
56+
57+ #[ cfg( not( target_os = "android" ) ) ]
58+ unsafe fn cvt_pread64 ( fd : c_int , buf : * mut c_void , count : usize , offset : i64 )
59+ -> io:: Result < isize >
60+ {
61+ #[ cfg( any( target_os = "linux" , target_os = "emscripten" ) ) ]
62+ use libc:: pread64;
63+ #[ cfg( not( any( target_os = "linux" , target_os = "emscripten" ) ) ) ]
64+ use libc:: pread as pread64;
65+ cvt ( pread64 ( fd, buf, count, offset) )
66+ }
67+
7568 unsafe {
7669 cvt_pread64 ( self . fd ,
7770 buf. as_mut_ptr ( ) as * mut c_void ,
7871 buf. len ( ) ,
79- offset as off64_t )
72+ offset as i64 )
8073 . map ( |n| n as usize )
8174 }
8275 }
@@ -91,11 +84,25 @@ impl FileDesc {
9184 }
9285
9386 pub fn write_at ( & self , buf : & [ u8 ] , offset : u64 ) -> io:: Result < usize > {
87+ #[ cfg( target_os = "android" ) ]
88+ use super :: android:: cvt_pwrite64;
89+
90+ #[ cfg( not( target_os = "android" ) ) ]
91+ unsafe fn cvt_pwrite64 ( fd : c_int , buf : * const c_void , count : usize , offset : i64 )
92+ -> io:: Result < isize >
93+ {
94+ #[ cfg( any( target_os = "linux" , target_os = "emscripten" ) ) ]
95+ use libc:: pwrite64;
96+ #[ cfg( not( any( target_os = "linux" , target_os = "emscripten" ) ) ) ]
97+ use libc:: pwrite as pwrite64;
98+ cvt ( pwrite64 ( fd, buf, count, offset) )
99+ }
100+
94101 unsafe {
95102 cvt_pwrite64 ( self . fd ,
96103 buf. as_ptr ( ) as * const c_void ,
97104 buf. len ( ) ,
98- offset as off64_t )
105+ offset as i64 )
99106 . map ( |n| n as usize )
100107 }
101108 }
0 commit comments