@@ -18,27 +18,6 @@ use sys::cvt;
18
18
use sys_common:: AsInner ;
19
19
use sys_common:: io:: read_to_end_uninitialized;
20
20
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
-
42
21
pub struct FileDesc {
43
22
fd : c_int ,
44
23
}
@@ -72,11 +51,25 @@ impl FileDesc {
72
51
}
73
52
74
53
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
+
75
68
unsafe {
76
69
cvt_pread64 ( self . fd ,
77
70
buf. as_mut_ptr ( ) as * mut c_void ,
78
71
buf. len ( ) ,
79
- offset as off64_t )
72
+ offset as i64 )
80
73
. map ( |n| n as usize )
81
74
}
82
75
}
@@ -91,11 +84,25 @@ impl FileDesc {
91
84
}
92
85
93
86
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
+
94
101
unsafe {
95
102
cvt_pwrite64 ( self . fd ,
96
103
buf. as_ptr ( ) as * const c_void ,
97
104
buf. len ( ) ,
98
- offset as off64_t )
105
+ offset as i64 )
99
106
. map ( |n| n as usize )
100
107
}
101
108
}
0 commit comments