Skip to content

Commit aa6f5e2

Browse files
committed
Add FD_* functions/macros for redox; implementations copied from linux_like
1 parent 6eca767 commit aa6f5e2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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)