Skip to content

redox: make CMSG_ALIGN, CMSG_LEN, and CMSG_SPACE const functions #4441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/unix/redox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,8 +1014,19 @@ pub const PRIO_PROCESS: c_int = 0;
pub const PRIO_PGRP: c_int = 1;
pub const PRIO_USER: c_int = 2;

// wait.h
f! {
//sys/socket.h
pub {const} fn CMSG_ALIGN(len: size_t) -> size_t {
(len + mem::size_of::<size_t>() - 1) & !(mem::size_of::<size_t>() - 1)
}
pub {const} fn CMSG_LEN(length: c_uint) -> c_uint {
(CMSG_ALIGN(mem::size_of::<cmsghdr>()) + length as usize) as c_uint
}
pub {const} fn CMSG_SPACE(len: c_uint) -> c_uint {
(CMSG_ALIGN(len as size_t) + CMSG_ALIGN(mem::size_of::<cmsghdr>())) as c_uint
}

// wait.h
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;
Expand Down Expand Up @@ -1228,12 +1239,9 @@ extern "C" {
pub fn setrlimit(resource: c_int, rlim: *const crate::rlimit) -> c_int;

// sys/socket.h
pub fn CMSG_ALIGN(len: size_t) -> size_t;
pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar;
pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr;
pub fn CMSG_LEN(len: c_uint) -> c_uint;
pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr;
pub fn CMSG_SPACE(len: c_uint) -> c_uint;
pub fn bind(
socket: c_int,
address: *const crate::sockaddr,
Expand Down
Loading