|
18 | 18 |
|
19 | 19 | #![cfg(target_os = "android")]
|
20 | 20 |
|
21 |
| -use libc::{c_int, c_void, sighandler_t, size_t, ssize_t}; |
22 |
| -use libc::{ftruncate, pread, pwrite}; |
| 21 | +use libc::{c_int, sighandler_t}; |
23 | 22 |
|
24 |
| -use super::{cvt, cvt_r, weak::weak}; |
25 |
| -use crate::io; |
| 23 | +use super::weak::weak; |
26 | 24 |
|
27 | 25 | // The `log2` and `log2f` functions apparently appeared in android-18, or at
|
28 | 26 | // least you can see they're not present in the android-17 header [1] and they
|
@@ -81,87 +79,3 @@ pub unsafe fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t {
|
81 | 79 | let f = f.expect("neither `signal` nor `bsd_signal` symbols found");
|
82 | 80 | f(signum, handler)
|
83 | 81 | }
|
84 |
| - |
85 |
| -// The `ftruncate64` symbol apparently appeared in android-12, so we do some |
86 |
| -// dynamic detection to see if we can figure out whether `ftruncate64` exists. |
87 |
| -// |
88 |
| -// If it doesn't we just fall back to `ftruncate`, generating an error for |
89 |
| -// too-large values. |
90 |
| -#[cfg(target_pointer_width = "32")] |
91 |
| -pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> { |
92 |
| - weak!(fn ftruncate64(c_int, i64) -> c_int); |
93 |
| - |
94 |
| - unsafe { |
95 |
| - match ftruncate64.get() { |
96 |
| - Some(f) => cvt_r(|| f(fd, size as i64)).map(drop), |
97 |
| - None => { |
98 |
| - if size > i32::MAX as u64 { |
99 |
| - Err(io::Error::new_const(io::ErrorKind::InvalidInput, &"cannot truncate >2GB")) |
100 |
| - } else { |
101 |
| - cvt_r(|| ftruncate(fd, size as i32)).map(drop) |
102 |
| - } |
103 |
| - } |
104 |
| - } |
105 |
| - } |
106 |
| -} |
107 |
| - |
108 |
| -#[cfg(target_pointer_width = "64")] |
109 |
| -pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> { |
110 |
| - unsafe { cvt_r(|| ftruncate(fd, size as i64)).map(drop) } |
111 |
| -} |
112 |
| - |
113 |
| -#[cfg(target_pointer_width = "32")] |
114 |
| -pub unsafe fn cvt_pread64( |
115 |
| - fd: c_int, |
116 |
| - buf: *mut c_void, |
117 |
| - count: size_t, |
118 |
| - offset: i64, |
119 |
| -) -> io::Result<ssize_t> { |
120 |
| - use crate::convert::TryInto; |
121 |
| - weak!(fn pread64(c_int, *mut c_void, size_t, i64) -> ssize_t); |
122 |
| - pread64.get().map(|f| cvt(f(fd, buf, count, offset))).unwrap_or_else(|| { |
123 |
| - if let Ok(o) = offset.try_into() { |
124 |
| - cvt(pread(fd, buf, count, o)) |
125 |
| - } else { |
126 |
| - Err(io::Error::new_const(io::ErrorKind::InvalidInput, &"cannot pread >2GB")) |
127 |
| - } |
128 |
| - }) |
129 |
| -} |
130 |
| - |
131 |
| -#[cfg(target_pointer_width = "32")] |
132 |
| -pub unsafe fn cvt_pwrite64( |
133 |
| - fd: c_int, |
134 |
| - buf: *const c_void, |
135 |
| - count: size_t, |
136 |
| - offset: i64, |
137 |
| -) -> io::Result<ssize_t> { |
138 |
| - use crate::convert::TryInto; |
139 |
| - weak!(fn pwrite64(c_int, *const c_void, size_t, i64) -> ssize_t); |
140 |
| - pwrite64.get().map(|f| cvt(f(fd, buf, count, offset))).unwrap_or_else(|| { |
141 |
| - if let Ok(o) = offset.try_into() { |
142 |
| - cvt(pwrite(fd, buf, count, o)) |
143 |
| - } else { |
144 |
| - Err(io::Error::new_const(io::ErrorKind::InvalidInput, &"cannot pwrite >2GB")) |
145 |
| - } |
146 |
| - }) |
147 |
| -} |
148 |
| - |
149 |
| -#[cfg(target_pointer_width = "64")] |
150 |
| -pub unsafe fn cvt_pread64( |
151 |
| - fd: c_int, |
152 |
| - buf: *mut c_void, |
153 |
| - count: size_t, |
154 |
| - offset: i64, |
155 |
| -) -> io::Result<ssize_t> { |
156 |
| - cvt(pread(fd, buf, count, offset)) |
157 |
| -} |
158 |
| - |
159 |
| -#[cfg(target_pointer_width = "64")] |
160 |
| -pub unsafe fn cvt_pwrite64( |
161 |
| - fd: c_int, |
162 |
| - buf: *const c_void, |
163 |
| - count: size_t, |
164 |
| - offset: i64, |
165 |
| -) -> io::Result<ssize_t> { |
166 |
| - cvt(pwrite(fd, buf, count, offset)) |
167 |
| -} |
0 commit comments