Skip to content

Commit

Permalink
Auto merge of #1621 - coolreader18:fdset-redox-ai-android, r=gnzlbg
Browse files Browse the repository at this point in the history
Add Redox FD_* function-macros and Android AI_* constants

I'm not sure if I'm allowed to add multiple, separate APIs in the same PR, but I guess they're both for uncommon/exotic platforms?

The `AI_*` constants were taken from `usr/include/netdb.h` on my Termux install; the `FD_` functions were taken from `linux_like/mod.rs`.
  • Loading branch information
bors committed Dec 27, 2019
2 parents 80c6c64 + aa6f5e2 commit 74ff412
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,21 @@ pub const RTLD_NOLOAD: ::c_int = 0x4;

pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t;

pub const AI_PASSIVE: ::c_int = 0x00000001;
pub const AI_CANONNAME: ::c_int = 0x00000002;
pub const AI_NUMERICHOST: ::c_int = 0x00000004;
pub const AI_NUMERICSERV: ::c_int = 0x00000008;
pub const AI_MASK: ::c_int = AI_PASSIVE
| AI_CANONNAME
| AI_NUMERICHOST
| AI_NUMERICSERV
| AI_ADDRCONFIG;
pub const AI_ALL: ::c_int = 0x00000100;
pub const AI_V4MAPPED_CFG: ::c_int = 0x00000200;
pub const AI_ADDRCONFIG: ::c_int = 0x00000400;
pub const AI_V4MAPPED: ::c_int = 0x00000800;
pub const AI_DEFAULT: ::c_int = AI_V4MAPPED_CFG | AI_ADDRCONFIG;

pub const LINUX_REBOOT_MAGIC1: ::c_int = 0xfee1dead;
pub const LINUX_REBOOT_MAGIC2: ::c_int = 672274793;
pub const LINUX_REBOOT_MAGIC2A: ::c_int = 85072278;
Expand Down
26 changes: 26 additions & 0 deletions src/unix/redox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,32 @@ f! {
pub fn WCOREDUMP(status: ::c_int) -> bool {
(status & 0x80) != 0
}

pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
let fd = fd as usize;
let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8;
(*set).fds_bits[fd / size] &= !(1 << (fd % size));
return
}

pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool {
let fd = fd as usize;
let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8;
return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0
}

pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () {
let fd = fd as usize;
let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8;
(*set).fds_bits[fd / size] |= 1 << (fd % size);
return
}

pub fn FD_ZERO(set: *mut fd_set) -> () {
for slot in (*set).fds_bits.iter_mut() {
*slot = 0;
}
}
}

extern "C" {
Expand Down

0 comments on commit 74ff412

Please sign in to comment.