|
1 | 1 | //! Apple (ios/darwin)-specific definitions
|
2 | 2 | //!
|
3 | 3 | //! This covers *-apple-* triples currently
|
| 4 | +use dox::mem; |
4 | 5 |
|
5 | 6 | pub type c_char = i8;
|
6 | 7 | pub type clock_t = c_ulong;
|
@@ -2383,7 +2384,45 @@ pub const SF_IMMUTABLE: ::c_uint = 0x00020000;
|
2383 | 2384 | pub const SF_APPEND: ::c_uint = 0x00040000;
|
2384 | 2385 | pub const UF_HIDDEN: ::c_uint = 0x00008000;
|
2385 | 2386 |
|
| 2387 | +fn __DARWIN_ALIGN32(p: usize) -> usize { |
| 2388 | + const __DARWIN_ALIGNBYTES32: usize = mem::size_of::<u32>() - 1; |
| 2389 | + p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32 |
| 2390 | +} |
| 2391 | + |
2386 | 2392 | f! {
|
| 2393 | + pub fn CMSG_NXTHDR(mhdr: *const ::msghdr, |
| 2394 | + cmsg: *const ::cmsghdr) -> *mut ::cmsghdr { |
| 2395 | + if cmsg.is_null() { |
| 2396 | + return ::CMSG_FIRSTHDR(mhdr); |
| 2397 | + }; |
| 2398 | + let cmsg_len = (*cmsg).cmsg_len as usize; |
| 2399 | + let next = cmsg as usize + __DARWIN_ALIGN32(cmsg_len as usize) |
| 2400 | + + __DARWIN_ALIGN32(mem::size_of::<::cmsghdr>()); |
| 2401 | + let max = (*mhdr).msg_control as usize |
| 2402 | + + (*mhdr).msg_controllen as usize; |
| 2403 | + if next > max { |
| 2404 | + 0 as *mut ::cmsghdr |
| 2405 | + } else { |
| 2406 | + next as *mut ::cmsghdr |
| 2407 | + } |
| 2408 | + } |
| 2409 | + |
| 2410 | + pub fn CMSG_DATA(cmsg: *const ::cmsghdr) -> *mut ::c_uchar { |
| 2411 | + (cmsg as *mut ::c_uchar) |
| 2412 | + .offset(__DARWIN_ALIGN32(mem::size_of::<::cmsghdr>()) as isize) |
| 2413 | + } |
| 2414 | + |
| 2415 | + pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { |
| 2416 | + (__DARWIN_ALIGN32(mem::size_of::<::cmsghdr>()) |
| 2417 | + + __DARWIN_ALIGN32(length as usize)) |
| 2418 | + as ::c_uint |
| 2419 | + } |
| 2420 | + |
| 2421 | + pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { |
| 2422 | + __DARWIN_ALIGN32(mem::size_of::<::cmsghdr>() + length as usize) |
| 2423 | + as ::c_uint |
| 2424 | + } |
| 2425 | + |
2387 | 2426 | pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
|
2388 | 2427 | status >> 8
|
2389 | 2428 | }
|
|
0 commit comments