Skip to content

Commit 74ff412

Browse files
committed
Auto merge of #1621 - coolreader18:fdset-redox-ai-android, r=gnzlbg
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`.
2 parents 80c6c64 + aa6f5e2 commit 74ff412

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/unix/linux_like/android/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,21 @@ pub const RTLD_NOLOAD: ::c_int = 0x4;
11571157

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

1160+
pub const AI_PASSIVE: ::c_int = 0x00000001;
1161+
pub const AI_CANONNAME: ::c_int = 0x00000002;
1162+
pub const AI_NUMERICHOST: ::c_int = 0x00000004;
1163+
pub const AI_NUMERICSERV: ::c_int = 0x00000008;
1164+
pub const AI_MASK: ::c_int = AI_PASSIVE
1165+
| AI_CANONNAME
1166+
| AI_NUMERICHOST
1167+
| AI_NUMERICSERV
1168+
| AI_ADDRCONFIG;
1169+
pub const AI_ALL: ::c_int = 0x00000100;
1170+
pub const AI_V4MAPPED_CFG: ::c_int = 0x00000200;
1171+
pub const AI_ADDRCONFIG: ::c_int = 0x00000400;
1172+
pub const AI_V4MAPPED: ::c_int = 0x00000800;
1173+
pub const AI_DEFAULT: ::c_int = AI_V4MAPPED_CFG | AI_ADDRCONFIG;
1174+
11601175
pub const LINUX_REBOOT_MAGIC1: ::c_int = 0xfee1dead;
11611176
pub const LINUX_REBOOT_MAGIC2: ::c_int = 672274793;
11621177
pub const LINUX_REBOOT_MAGIC2A: ::c_int = 85072278;

src/unix/redox/mod.rs

+26
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,32 @@ f! {
839839
pub fn WCOREDUMP(status: ::c_int) -> bool {
840840
(status & 0x80) != 0
841841
}
842+
843+
pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
844+
let fd = fd as usize;
845+
let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8;
846+
(*set).fds_bits[fd / size] &= !(1 << (fd % size));
847+
return
848+
}
849+
850+
pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool {
851+
let fd = fd as usize;
852+
let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8;
853+
return ((*set).fds_bits[fd / size] & (1 << (fd % size))) != 0
854+
}
855+
856+
pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () {
857+
let fd = fd as usize;
858+
let size = ::mem::size_of_val(&(*set).fds_bits[0]) * 8;
859+
(*set).fds_bits[fd / size] |= 1 << (fd % size);
860+
return
861+
}
862+
863+
pub fn FD_ZERO(set: *mut fd_set) -> () {
864+
for slot in (*set).fds_bits.iter_mut() {
865+
*slot = 0;
866+
}
867+
}
842868
}
843869

844870
extern "C" {

0 commit comments

Comments
 (0)