std: Add compatibility with android-9

The Gecko folks currently use Android API level 9 for their builds, so they're
requesting that we move back our minimum supported API level from 18 to 9. Turns
out, ABI-wise at least, there's not that many changes we need to take care of.
The `ftruncate64` API appeared in android-12 and the `log2` and `log2f` APIs
appeared in android-18. We can have a simple shim for `ftruncate64` which falls
back on `ftruncate` and the `log2` function can be approximated with just
`ln(f) / ln(2)`.

This should at least get the standard library building on API level 9, although
the tests aren't quite happening there just yet. As we seem to be growing a
number of Android compatibility shims, they're now centralized in a common
`sys::android` module.
This commit is contained in:
Alex Crichton
2016-04-25 13:39:05 -07:00
parent cfae4dea87
commit c31e2e77ed
5 changed files with 138 additions and 36 deletions

View File

@@ -27,7 +27,7 @@ use sys_common::{AsInner, FromInner};
#[cfg(any(target_os = "linux", target_os = "emscripten"))]
use libc::{stat64, fstat64, lstat64, off64_t, ftruncate64, lseek64, dirent64, readdir64_r, open64};
#[cfg(target_os = "android")]
use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, off64_t, ftruncate64, lseek64,
use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, off64_t, lseek64,
dirent as dirent64, open as open64};
#[cfg(not(any(target_os = "linux",
target_os = "emscripten",
@@ -475,10 +475,13 @@ impl File {
}
pub fn truncate(&self, size: u64) -> io::Result<()> {
cvt_r(|| unsafe {
#[cfg(target_os = "android")]
return ::sys::android::ftruncate64(self.0.raw(), size);
#[cfg(not(target_os = "android"))]
return cvt_r(|| unsafe {
ftruncate64(self.0.raw(), size as off64_t)
})?;
Ok(())
}).map(|_| ());
}
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {