Skip to content

Commit eb422b0

Browse files
authored
Add FD_* macros (#45)
1 parent 3092b39 commit eb422b0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/lib.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,41 @@ pub mod cmsg_macros {
131131
}
132132
}
133133

134+
#[cfg(feature = "general")]
135+
pub mod select_macros {
136+
use crate::ctypes::c_int;
137+
use crate::general::__kernel_fd_set;
138+
use core::mem::size_of;
139+
140+
pub unsafe fn FD_CLR(fd: c_int, set: *mut __kernel_fd_set) {
141+
let bytes = set as *mut u8;
142+
if fd >= 0 {
143+
*bytes.offset((fd / 8) as isize) &= !(1 << (fd % 8));
144+
}
145+
}
146+
147+
pub unsafe fn FD_SET(fd: c_int, set: *mut __kernel_fd_set) {
148+
let bytes = set as *mut u8;
149+
if fd >= 0 {
150+
*bytes.offset((fd / 8) as isize) |= 1 << (fd % 8);
151+
}
152+
}
153+
154+
pub unsafe fn FD_ISSET(fd: c_int, set: *const __kernel_fd_set) -> bool {
155+
let bytes = set as *const u8;
156+
if fd >= 0 {
157+
*bytes.offset((fd / 8) as isize) & (1 << (fd % 8)) != 0
158+
} else {
159+
false
160+
}
161+
}
162+
163+
pub unsafe fn FD_ZERO(set: *mut __kernel_fd_set) {
164+
let bytes = set as *mut u8;
165+
core::ptr::write_bytes(bytes, 0, size_of::<__kernel_fd_set>());
166+
}
167+
}
168+
134169
// The rest of this file is auto-generated!
135170
#[cfg(feature = "errno")]
136171
#[cfg(target_arch = "arm")]

0 commit comments

Comments
 (0)