Skip to content

Commit b1de6c9

Browse files
authored
Make CMSG_* functions const. (#59)
Following the libc crate which made its `CMSG_*` functions const, make linux-raw-sys's `CMSG_*` functions const. Some of them can't be with our MSRV of 1.48, so add comments for those.
1 parent bc9a83b commit b1de6c9

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,25 @@ pub mod cmsg_macros {
8585
use core::mem::size_of;
8686
use core::ptr;
8787

88-
pub unsafe fn CMSG_ALIGN(len: c_uint) -> c_uint {
88+
pub const unsafe fn CMSG_ALIGN(len: c_uint) -> c_uint {
8989
let c_long_size = size_of::<c_long>() as c_uint;
9090
(len + c_long_size - 1) & !(c_long_size - 1)
9191
}
9292

93+
// TODO: In Rust 1.63 we can make this a `const fn`.
9394
pub unsafe fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
9495
(cmsg as *mut c_uchar).offset(size_of::<cmsghdr>() as isize)
9596
}
9697

97-
pub unsafe fn CMSG_SPACE(len: c_uint) -> c_uint {
98+
pub const unsafe fn CMSG_SPACE(len: c_uint) -> c_uint {
9899
size_of::<cmsghdr>() as c_uint + CMSG_ALIGN(len)
99100
}
100101

101-
pub unsafe fn CMSG_LEN(len: c_uint) -> c_uint {
102+
pub const unsafe fn CMSG_LEN(len: c_uint) -> c_uint {
102103
size_of::<cmsghdr>() as c_uint + len
103104
}
104105

106+
// TODO: In Rust 1.63 we can make this a `const fn`.
105107
pub unsafe fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr {
106108
if (*mhdr).msg_controllen < size_of::<cmsghdr>() as _ {
107109
return ptr::null_mut();

0 commit comments

Comments
 (0)