diff options
author | JohnTitor <huyuumi.dev@gmail.com> | 2021-03-30 15:28:55 +0900 |
---|---|---|
committer | JohnTitor <huyuumi.dev@gmail.com> | 2021-03-30 17:37:13 +0900 |
commit | e187543fddad0f252dae395508a47748dbf963e1 (patch) | |
tree | 5eb4fbb9973cd7cd7e37089732f7459f8ce520b1 | |
parent | f913fc53a682c7b836bdf2ac0da601f2d8334b32 (diff) | |
download | rust-libc-e187543fddad0f252dae395508a47748dbf963e1.tar.gz |
Constify `CMSG_SPACE` for all the targets
-rw-r--r-- | src/fuchsia/mod.rs | 4 | ||||
-rw-r--r-- | src/unix/bsd/apple/mod.rs | 11 | ||||
-rw-r--r-- | src/unix/bsd/freebsdlike/dragonfly/mod.rs | 8 | ||||
-rw-r--r-- | src/unix/bsd/freebsdlike/freebsd/mod.rs | 8 | ||||
-rw-r--r-- | src/unix/bsd/netbsdlike/netbsd/mod.rs | 8 | ||||
-rw-r--r-- | src/unix/bsd/netbsdlike/openbsd/mod.rs | 8 | ||||
-rw-r--r-- | src/unix/solarish/mod.rs | 14 | ||||
-rwxr-xr-x | src/vxworks/mod.rs | 4 |
8 files changed, 40 insertions, 25 deletions
diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index f179923ac4..d3d9e45442 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -3256,12 +3256,12 @@ f! { } } - pub fn CMSG_ALIGN(len: ::size_t) -> ::size_t { + pub {const} fn CMSG_ALIGN(len: ::size_t) -> ::size_t { (len + ::mem::size_of::<::size_t>() - 1) & !(::mem::size_of::<::size_t>() - 1) } - pub fn CMSG_SPACE(len: ::c_uint) -> ::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 } diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 73933d8c5e..4c48221135 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -3366,7 +3366,12 @@ pub const MNT_WAIT: ::c_int = 1; pub const MNT_NOWAIT: ::c_int = 2; cfg_if! { - if #[cfg(libc_const_size_of)] { + if #[cfg(libc_const_extern_fn)] { + const fn __DARWIN_ALIGN32(p: usize) -> usize { + const __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1; + p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32 + } + } else if #[cfg(libc_const_size_of)] { fn __DARWIN_ALIGN32(p: usize) -> usize { const __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1; p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32 @@ -3388,7 +3393,7 @@ f! { let cmsg_len = (*cmsg).cmsg_len as usize; let next = cmsg as usize + __DARWIN_ALIGN32(cmsg_len as usize); let max = (*mhdr).msg_control as usize - + (*mhdr).msg_controllen as usize; + + (*mhdr).msg_controllen as usize; if next + __DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>()) > max { 0 as *mut ::cmsghdr } else { @@ -3401,7 +3406,7 @@ f! { .offset(__DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>()) as isize) } - pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { + pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { (__DARWIN_ALIGN32(::mem::size_of::<::cmsghdr>()) + __DARWIN_ALIGN32(length as usize)) as ::c_uint diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index 7056cc5484..2a803bd197 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -1020,8 +1020,10 @@ pub const SF_XLINK: ::c_ulong = 0x01000000; pub const UTIME_OMIT: c_long = -2; pub const UTIME_NOW: c_long = -1; -fn _CMSG_ALIGN(n: usize) -> usize { - (n + 3) & !3 +const_fn! { + {const} fn _CMSG_ALIGN(n: usize) -> usize { + (n + 3) & !3 + } } f! { @@ -1050,7 +1052,7 @@ f! { } } - pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { + pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { (_CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) + _CMSG_ALIGN(length as usize)) as ::c_uint } diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 75189cc761..6a6033dc08 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -1216,8 +1216,10 @@ pub const F_READAHEAD: ::c_int = 15; pub const F_RDAHEAD: ::c_int = 16; pub const F_DUP2FD_CLOEXEC: ::c_int = 18; -fn _ALIGN(p: usize) -> usize { - (p + _ALIGNBYTES) & !_ALIGNBYTES +const_fn! { + {const} fn _ALIGN(p: usize) -> usize { + (p + _ALIGNBYTES) & !_ALIGNBYTES + } } f! { @@ -1248,7 +1250,7 @@ f! { } } - pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { + pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { (_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize)) as ::c_uint } diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index b789f47ec9..82b13e9f4d 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -1748,8 +1748,10 @@ pub const SF_SNAPSHOT: ::c_ulong = 0x00200000; pub const SF_LOG: ::c_ulong = 0x00400000; pub const SF_SNAPINVAL: ::c_ulong = 0x00800000; -fn _ALIGN(p: usize) -> usize { - (p + _ALIGNBYTES) & !_ALIGNBYTES +const_fn! { + {const} fn _ALIGN(p: usize) -> usize { + (p + _ALIGNBYTES) & !_ALIGNBYTES + } } f! { @@ -1780,7 +1782,7 @@ f! { } } - pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { + pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { (_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize)) as ::c_uint } diff --git a/src/unix/bsd/netbsdlike/openbsd/mod.rs b/src/unix/bsd/netbsdlike/openbsd/mod.rs index 06068115f8..a4b1d31194 100644 --- a/src/unix/bsd/netbsdlike/openbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/openbsd/mod.rs @@ -1397,8 +1397,10 @@ pub const PTRACE_FORK: ::c_int = 0x0002; pub const WCONTINUED: ::c_int = 8; -fn _ALIGN(p: usize) -> usize { - (p + _ALIGNBYTES) & !_ALIGNBYTES +const_fn! { + {const} fn _ALIGN(p: usize) -> usize { + (p + _ALIGNBYTES) & !_ALIGNBYTES + } } f! { @@ -1429,7 +1431,7 @@ f! { } } - pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { + pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { (_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize)) as ::c_uint } diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs index 2db4916a52..994ce7e52a 100644 --- a/src/unix/solarish/mod.rs +++ b/src/unix/solarish/mod.rs @@ -2103,12 +2103,14 @@ const _CMSG_HDR_ALIGNMENT: usize = 4; const _CMSG_DATA_ALIGNMENT: usize = ::mem::size_of::<::c_int>(); -fn _CMSG_HDR_ALIGN(p: usize) -> usize { - (p + _CMSG_HDR_ALIGNMENT - 1) & !(_CMSG_HDR_ALIGNMENT - 1) -} +const_fn! { + {const} fn _CMSG_HDR_ALIGN(p: usize) -> usize { + (p + _CMSG_HDR_ALIGNMENT - 1) & !(_CMSG_HDR_ALIGNMENT - 1) + } -fn _CMSG_DATA_ALIGN(p: usize) -> usize { - (p + _CMSG_DATA_ALIGNMENT - 1) & !(_CMSG_DATA_ALIGNMENT - 1) + {const} fn _CMSG_DATA_ALIGN(p: usize) -> usize { + (p + _CMSG_DATA_ALIGNMENT - 1) & !(_CMSG_DATA_ALIGNMENT - 1) + } } f! { @@ -2146,7 +2148,7 @@ f! { } } - pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { + pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { _CMSG_HDR_ALIGN(::mem::size_of::<::cmsghdr>() as usize + length as usize) as ::c_uint } diff --git a/src/vxworks/mod.rs b/src/vxworks/mod.rs index 668a7fcc96..704dac7f5c 100755 --- a/src/vxworks/mod.rs +++ b/src/vxworks/mod.rs @@ -1040,7 +1040,7 @@ impl ::Clone for fpos_t { } f! { - pub fn CMSG_ALIGN(len: usize) -> usize { + pub {const} fn CMSG_ALIGN(len: usize) -> usize { len + ::mem::size_of::<usize>() - 1 & !(::mem::size_of::<usize>() - 1) } @@ -1071,7 +1071,7 @@ f! { .offset(CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) as isize) } - pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { + pub {const} fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { (CMSG_ALIGN(length as usize) + CMSG_ALIGN(::mem::size_of::<cmsghdr>())) as ::c_uint } |