Skip to content

Commit

Permalink
support android build
Browse files Browse the repository at this point in the history
  • Loading branch information
warthog618 committed Jun 10, 2024
1 parent 922bd1b commit 088b278
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ use std::fmt;
use std::fs;
use std::mem;
use std::ops::Range;
#[cfg(target_os = "linux")]
use std::os::linux::fs::MetadataExt;
#[cfg(target_os = "android")]
use std::os::android::fs::MetadataExt;
use std::os::unix::prelude::{AsFd, AsRawFd, BorrowedFd, OsStrExt};
use std::path::{Path, PathBuf};
use std::time::Duration;
Expand Down
12 changes: 9 additions & 3 deletions uapi/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ pub fn has_event(f: &File) -> Result<bool> {
wait_event(f, Duration::ZERO)
}

// workaround musl libc::ioctl() having a different signature
#[cfg(target_env = "musl")]
// workaround musl and android libc::ioctl() having a different signature
#[cfg(any(target_env = "musl", target_os = "android"))]
pub(crate) type IoctlRequestType = libc::c_int;
#[cfg(not(target_env = "musl"))]
#[cfg(not(any(target_env = "musl", target_os = "android")))]
pub(crate) type IoctlRequestType = libc::c_ulong;

macro_rules! ior {
Expand Down Expand Up @@ -192,9 +192,15 @@ pub enum Error {
impl Error {
/// Create an error from the current errno value.
#[inline]
#[cfg(target_os = "linux")]
pub fn from_errno() -> Error {
Error::Os(Errno(unsafe { *libc::__errno_location() }))
}
#[inline]
#[cfg(target_os = "android")]
pub fn from_errno() -> Error {
Error::Os(Errno(std::io::Error::last_os_error().raw_os_error().unwrap()))
}
}

/// A failure to read sufficient bytes to construct an object.
Expand Down

0 comments on commit 088b278

Please sign in to comment.