Skip to content

Commit

Permalink
Add FD_* macros (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
notgull authored Jan 18, 2023
1 parent 3092b39 commit eb422b0
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,41 @@ pub mod cmsg_macros {
}
}

#[cfg(feature = "general")]
pub mod select_macros {
use crate::ctypes::c_int;
use crate::general::__kernel_fd_set;
use core::mem::size_of;

pub unsafe fn FD_CLR(fd: c_int, set: *mut __kernel_fd_set) {
let bytes = set as *mut u8;
if fd >= 0 {
*bytes.offset((fd / 8) as isize) &= !(1 << (fd % 8));
}
}

pub unsafe fn FD_SET(fd: c_int, set: *mut __kernel_fd_set) {
let bytes = set as *mut u8;
if fd >= 0 {
*bytes.offset((fd / 8) as isize) |= 1 << (fd % 8);
}
}

pub unsafe fn FD_ISSET(fd: c_int, set: *const __kernel_fd_set) -> bool {
let bytes = set as *const u8;
if fd >= 0 {
*bytes.offset((fd / 8) as isize) & (1 << (fd % 8)) != 0
} else {
false
}
}

pub unsafe fn FD_ZERO(set: *mut __kernel_fd_set) {
let bytes = set as *mut u8;
core::ptr::write_bytes(bytes, 0, size_of::<__kernel_fd_set>());
}
}

// The rest of this file is auto-generated!
#[cfg(feature = "errno")]
#[cfg(target_arch = "arm")]
Expand Down

0 comments on commit eb422b0

Please sign in to comment.