28
28
29
29
#![ cfg( target_os = "android" ) ]
30
30
31
- use libc:: { c_int, sighandler_t} ;
31
+ use libc:: { c_int, c_void, sighandler_t, size_t, ssize_t} ;
32
+ use libc:: { ftruncate, pread, pwrite} ;
32
33
33
34
use io;
34
- use sys :: cvt_r;
35
+ use super :: { cvt , cvt_r} ;
35
36
36
37
// The `log2` and `log2f` functions apparently appeared in android-18, or at
37
38
// least you can see they're not present in the android-17 header [1] and they
@@ -99,10 +100,6 @@ pub unsafe fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t {
99
100
pub fn ftruncate64 ( fd : c_int , size : u64 ) -> io:: Result < ( ) > {
100
101
weak ! ( fn ftruncate64( c_int, i64 ) -> c_int) ;
101
102
102
- extern {
103
- fn ftruncate ( fd : c_int , off : i32 ) -> c_int ;
104
- }
105
-
106
103
unsafe {
107
104
match ftruncate64. get ( ) {
108
105
Some ( f) => cvt_r ( || f ( fd, size as i64 ) ) . map ( |_| ( ) ) ,
@@ -117,3 +114,35 @@ pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> {
117
114
}
118
115
}
119
116
}
117
+
118
+ pub unsafe fn cvt_pread64 ( fd : c_int , buf : * mut c_void , count : size_t , offset : i64 )
119
+ -> io:: Result < ssize_t >
120
+ {
121
+ weak ! ( fn pread64( c_int, * mut c_void, size_t, i64 ) -> ssize_t) ;
122
+ unsafe {
123
+ pread64. get ( ) . map ( |f| cvt ( f ( fd, buf, count, offset) ) ) . unwrap_or_else ( || {
124
+ if offset as u64 > i32:: max_value ( ) as u64 {
125
+ Err ( io:: Error :: new ( io:: Error :: InvalidInput ,
126
+ "cannot pread >2GB" ) )
127
+ } else {
128
+ cvt ( pread ( fd, buf, count, offset as i32 ) )
129
+ }
130
+ } )
131
+ }
132
+ }
133
+
134
+ pub unsafe fn cvt_pwrite64 ( fd : c_int , buf : * const c_void , count : size_t , offset : i64 )
135
+ -> io:: Result < ssize_t >
136
+ {
137
+ weak ! ( fn pwrite64( c_int, * const c_void, size_t, i64 ) -> ssize_t) ;
138
+ unsafe {
139
+ pwrite64. get ( ) . map ( |f| cvt ( f ( fd, buf, count, offset) ) ) . unwrap_or_else ( || {
140
+ if offset as u64 > i32:: max_value ( ) as u64 {
141
+ Err ( io:: Error :: new ( io:: Error :: InvalidInput ,
142
+ "cannot pwrite >2GB" ) )
143
+ } else {
144
+ cvt ( pwrite ( fd, buf, count, offset as i32 ) )
145
+ }
146
+ } )
147
+ }
148
+ }
0 commit comments