Skip to content

Commit 8ef04c0

Browse files
authored
Merge pull request #4441 from redox-os/redox-cmsg-const-fns
redox: make CMSG_ALIGN, CMSG_LEN, and CMSG_SPACE const functions
2 parents 4cdbb5e + b20a725 commit 8ef04c0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/unix/redox/mod.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -1014,8 +1014,19 @@ pub const PRIO_PROCESS: c_int = 0;
10141014
pub const PRIO_PGRP: c_int = 1;
10151015
pub const PRIO_USER: c_int = 2;
10161016

1017-
// wait.h
10181017
f! {
1018+
//sys/socket.h
1019+
pub {const} fn CMSG_ALIGN(len: size_t) -> size_t {
1020+
(len + mem::size_of::<size_t>() - 1) & !(mem::size_of::<size_t>() - 1)
1021+
}
1022+
pub {const} fn CMSG_LEN(length: c_uint) -> c_uint {
1023+
(CMSG_ALIGN(mem::size_of::<cmsghdr>()) + length as usize) as c_uint
1024+
}
1025+
pub {const} fn CMSG_SPACE(len: c_uint) -> c_uint {
1026+
(CMSG_ALIGN(len as size_t) + CMSG_ALIGN(mem::size_of::<cmsghdr>())) as c_uint
1027+
}
1028+
1029+
// wait.h
10191030
pub fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {
10201031
let fd = fd as usize;
10211032
let size = mem::size_of_val(&(*set).fds_bits[0]) * 8;
@@ -1228,12 +1239,9 @@ extern "C" {
12281239
pub fn setrlimit(resource: c_int, rlim: *const crate::rlimit) -> c_int;
12291240

12301241
// sys/socket.h
1231-
pub fn CMSG_ALIGN(len: size_t) -> size_t;
12321242
pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar;
12331243
pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr;
1234-
pub fn CMSG_LEN(len: c_uint) -> c_uint;
12351244
pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr;
1236-
pub fn CMSG_SPACE(len: c_uint) -> c_uint;
12371245
pub fn bind(
12381246
socket: c_int,
12391247
address: *const crate::sockaddr,

0 commit comments

Comments
 (0)