diff --git a/.travis.yml b/.travis.yml index 5a5bbebfa403e62b096266e94617d70a8a77c1f4..b50cb44a20376e7c78c4b2a14a05864f5a0c1d66 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,9 @@ matrix: - name: "Documentation" env: TARGET=x86_64-unknown-linux-gnu script: sh ci/dox.sh - install: true + install: + - travis_retry rustup component add rust-src + - travis_retry cargo install xargo stage: tools-and-build-and-tier1 - name: "Shellcheck" install: true @@ -48,7 +50,9 @@ matrix: script: sh ci/build.sh stage: tools-and-build-and-tier1 rust: nightly - install: true + install: + - travis_retry rustup component add rust-src + - travis_retry cargo install xargo - name: "Build Stable Rust" script: sh ci/build.sh stage: tools-and-build-and-tier1 diff --git a/ci/build.sh b/ci/build.sh index 69805fcbc281d5875ef4a371774fb924f0198303..74727a3313a1f2ec553b355d19ed44c85b4e60c4 100644 --- a/ci/build.sh +++ b/ci/build.sh @@ -11,7 +11,9 @@ OS=${TRAVIS_OS_NAME} echo "Testing Rust ${RUST} on ${OS}" test_target() { - TARGET="${1}" + CARGO="${1}" + TARGET="${2}" + NO_STD="${3}" opt= if [ "${TARGET}" = "x86_64-unknown-linux-gnux32" ]; then @@ -22,31 +24,38 @@ test_target() { opt="--release" fi - NO_STD= - case ${TARGET} in - thumbv*) - NO_STD=1 - ;; - esac - - rustup target add "${TARGET}" --toolchain "${RUST}" || true + # If there is a std component, fetch it: + if [ "${NO_STD}" != "1" ]; then + # FIXME: rustup often fails to download some artifacts due to network + # issues, so we retry this N times. + N=5 + n=0 + until [ $n -ge $N ] + do + if rustup target add "${TARGET}" --toolchain "${RUST}" ; then + break + fi + n=$((n+1)) + sleep 1 + done + fi # Test that libc builds without any default features (no libstd) - cargo "+${RUST}" build -vv $opt --no-default-features --target "${TARGET}" + "$CARGO" "+${RUST}" build -vv $opt --no-default-features --target "${TARGET}" # Test that libc builds with default features (e.g. libstd) # if the target supports libstd if [ "$NO_STD" != "1" ]; then - cargo "+${RUST}" build -vv $opt --target "${TARGET}" + "$CARGO" "+${RUST}" build -vv $opt --target "${TARGET}" fi # Test that libc builds with the `extra_traits` feature - cargo "+${RUST}" build -vv $opt --no-default-features --target "${TARGET}" \ + "$CARGO" "+${RUST}" build -vv $opt --no-default-features --target "${TARGET}" \ --features extra_traits # Also test that it builds with `extra_traits` and default features: if [ "$NO_STD" != "1" ]; then - cargo "+${RUST}" build -vv $opt --target "${TARGET}" \ + "$CARGO" "+${RUST}" build -vv $opt --target "${TARGET}" \ --features extra_traits fi } @@ -103,24 +112,15 @@ x86_64-unknown-cloudabi \ RUST_NIGHTLY_LINUX_TARGETS="\ aarch64-fuchsia \ -thumbv6m-none-eabi \ -thumbv7em-none-eabi \ -thumbv7em-none-eabihf \ -thumbv7m-none-eabi \ -thumbv7neon-linux-androideabi \ -thumbv7neon-unknown-linux-gnueabihf \ +armv5te-unknown-linux-gnueabi \ +armv5te-unknown-linux-musleabi \ +i686-pc-windows-gnu \ x86_64-fortanix-unknown-sgx \ x86_64-fuchsia \ +x86_64-pc-windows-gnu \ x86_64-unknown-linux-gnux32 \ x86_64-unknown-redox \ " -# FIXME: these do not have a rust-std component available -# aarch64-unknown-cloudabi armv7-unknown-cloudabi-eabihf -# i686-unknown-cloudabi powerpc-unknown-linux-gnuspe -# sparc-unknown-linux-gnu mips-unknown-linux-uclib -# i686-unknown-haiku mipsel-unknown-unknown-linux-uclib -# sparc64-unknown-netbsd x86_64-unknown-bitrig x86_64-unknown-haiku -# x86_64-unknown-openbsd i686-unknown-netbsd RUST_OSX_TARGETS="\ aarch64-apple-ios \ @@ -161,5 +161,45 @@ case "${OS}" in esac for TARGET in $TARGETS; do - test_target "$TARGET" + test_target cargo "$TARGET" done + +# FIXME: https://github.com/rust-lang/rust/issues/58564 +# sparc-unknown-linux-gnu +RUST_LINUX_NO_CORE_TARGETS="\ +x86_64-unknown-dragonfly \ +aarch64-pc-windows-msvc \ +aarch64-unknown-cloudabi \ +armebv7r-none-eabi \ +armebv7r-none-eabihf \ +armv7-unknown-cloudabi-eabihf \ +armv7r-none-eabi \ +armv7r-none-eabihf \ +i586-pc-windows-msvc \ +i686-pc-windows-msvc \ +i686-unknown-cloudabi \ +i686-unknown-haiku \ +i686-unknown-netbsd \ +nvptx64-nvidia-cuda \ +powerpc-unknown-linux-gnuspe \ +riscv32imac-unknown-none-elf \ +riscv32imc-unknown-none-elf \ +sparc64-unknown-netbsd \ +thumbv6m-none-eabi \ +thumbv7em-none-eabi \ +thumbv7em-none-eabihf \ +thumbv7m-none-eabi \ +thumbv7neon-linux-androideabi \ +thumbv7neon-unknown-linux-gnueabihf \ +thumbv8m.main-none-eabi \ +x86_64-pc-windows-msvc +x86_64-unknown-bitrig \ +x86_64-unknown-haiku \ +x86_64-unknown-openbsd +" + +if [ "${RUST}" = "nightly" ] && [ "${OS}" = "linux" ]; then + for TARGET in $RUST_LINUX_NO_CORE_TARGETS; do + test_target xargo "$TARGET" 1 + done +fi diff --git a/ci/dox.sh b/ci/dox.sh index 3456288a3791dd873e63c22e8d386543646fd7df..6c0f1a0c640232d9212ec4403f3cd4a8e5420a98 100644 --- a/ci/dox.sh +++ b/ci/dox.sh @@ -25,12 +25,30 @@ rm $PLATFORM_SUPPORT || true printf '### Platform-specific documentation\n' >> $PLATFORM_SUPPORT while read -r target; do - echo "documenting ${target}" + echo "documenting ${target}" - #rustdoc -o "$TARGET_DOC_DIR/${target}" --target "${target}" src/lib.rs --cfg cross_platform_docs \ - # --crate-name libc + case "${target}" in + *apple*) + # FIXME: + # We can't build docs of apple targets from Linux yet. + continue + ;; + *) + ;; + esac - echo "* [${target}](${target}/libc/index.html)" >> $PLATFORM_SUPPORT + rustup target add "${target}" || true + + # If cargo doc fails, then try xargo: + if ! cargo doc --target "${target}" \ + --no-default-features --features extra_traits ; then + xargo doc --target "${target}" \ + --no-default-features --features extra_traits + fi + + cp -r "target/${target}/doc" "${TARGET_DOC_DIR}/${target}" + + echo "* [${target}](${target}/libc/index.html)" >> $PLATFORM_SUPPORT done < targets # Replace <div class="platform_support"></div> with the contents of $PLATFORM_SUPPORT diff --git a/src/dox.rs b/src/dox.rs deleted file mode 100644 index d9899bb2249d38df8142a4ab1b239bbd8dc24753..0000000000000000000000000000000000000000 --- a/src/dox.rs +++ /dev/null @@ -1,211 +0,0 @@ -pub enum Option<T> { - Some(T), - None, -} -impl<T: Copy> Copy for Option<T> {} -impl<T: Clone> Clone for Option<T> { - fn clone(&self) -> Option<T> { - loop {} - } -} - -impl<T> Copy for *mut T {} -impl<T> Clone for *mut T { - fn clone(&self) -> *mut T { - loop {} - } -} - -impl<T> Copy for *const T {} -impl<T> Clone for *const T { - fn clone(&self) -> *const T { - loop {} - } -} - -pub trait Clone { - fn clone(&self) -> Self; -} - -#[lang = "copy"] -pub trait Copy {} - -#[lang = "freeze"] -pub trait Freeze {} - -#[lang = "sync"] -pub trait Sync {} -impl<T> Sync for T {} - -#[lang = "sized"] -pub trait Sized {} - -#[lang = "receiver"] -pub trait Receiver {} -impl<T: ?Sized> Receiver for &T {} -impl<T: ?Sized> Receiver for &mut T {} - -macro_rules! each_int { - ($mac:ident) => { - $mac!(u8); - $mac!(u16); - $mac!(u32); - $mac!(u64); - $mac!(usize); - each_signed_int!($mac); - }; -} - -macro_rules! each_signed_int { - ($mac:ident) => { - $mac!(i8); - $mac!(i16); - $mac!(i32); - $mac!(i64); - $mac!(isize); - }; -} - -#[lang = "div"] -pub trait Div<RHS = Self> { - type Output; - fn div(self, rhs: RHS) -> Self::Output; -} - -#[lang = "shl"] -pub trait Shl<RHS = Self> { - type Output; - fn shl(self, rhs: RHS) -> Self::Output; -} - -#[lang = "mul"] -pub trait Mul<RHS = Self> { - type Output; - fn mul(self, rhs: RHS) -> Self::Output; -} - -#[lang = "sub"] -pub trait Sub<RHS = Self> { - type Output; - fn sub(self, rhs: RHS) -> Self::Output; -} - -#[lang = "bitand"] -pub trait BitAnd<RHS = Self> { - type Output; - fn bitand(self, rhs: RHS) -> Self::Output; -} - -#[lang = "bitand_assign"] -pub trait BitAndAssign<RHS = Self> { - fn bitand_assign(&mut self, rhs: RHS); -} - -#[lang = "bitor"] -pub trait BitOr<RHS = Self> { - type Output; - fn bitor(self, rhs: RHS) -> Self::Output; -} - -#[lang = "bitor_assign"] -pub trait BitOrAssign<RHS = Self> { - fn bitor_assign(&mut self, rhs: RHS); -} - -#[lang = "bitxor"] -pub trait BitXor<RHS = Self> { - type Output; - fn bitxor(self, rhs: RHS) -> Self::Output; -} - -#[lang = "bitxor_assign"] -pub trait BitXorAssign<RHS = Self> { - fn bitxor_assign(&mut self, rhs: RHS); -} - -#[lang = "neg"] -pub trait Neg { - type Output; - fn neg(self) -> Self::Output; -} - -#[lang = "not"] -pub trait Not { - type Output; - fn not(self) -> Self::Output; -} - -#[lang = "add"] -pub trait Add<RHS = Self> { - type Output; - fn add(self, r: RHS) -> Self::Output; -} - -macro_rules! impl_traits { - ($($i:ident)*) => ($( - impl Div<$i> for $i { - type Output = $i; - fn div(self, rhs: $i) -> $i { self / rhs } - } - impl Shl<$i> for $i { - type Output = $i; - fn shl(self, rhs: $i) -> $i { self << rhs } - } - impl Mul for $i { - type Output = $i; - fn mul(self, rhs: $i) -> $i { self * rhs } - } - - impl Sub for $i { - type Output = $i; - fn sub(self, rhs: $i) -> $i { self - rhs } - } - impl BitAnd for $i { - type Output = $i; - fn bitand(self, rhs: $i) -> $i { self & rhs } - } - impl BitAndAssign for $i { - fn bitand_assign(&mut self, rhs: $i) { *self &= rhs; } - } - impl BitOr for $i { - type Output = $i; - fn bitor(self, rhs: $i) -> $i { self | rhs } - } - impl BitOrAssign for $i { - fn bitor_assign(&mut self, rhs: $i) { *self |= rhs; } - } - impl BitXor for $i { - type Output = $i; - fn bitxor(self, rhs: $i) -> $i { self ^ rhs } - } - impl BitXorAssign for $i { - fn bitxor_assign(&mut self, rhs: $i) { *self ^= rhs; } - } - impl Neg for $i { - type Output = $i; - fn neg(self) -> $i { -self } - } - impl Not for $i { - type Output = $i; - fn not(self) -> $i { !self } - } - impl Add<$i> for $i { - type Output = $i; - fn add(self, other: $i) -> $i { self + other } - } - impl Copy for $i {} - impl Clone for $i { - fn clone(&self) -> $i { loop {} } - } - )*) -} -each_int!(impl_traits); - -pub mod mem { - pub fn size_of_val<T>(_: &T) -> usize { - 4 - } - pub const fn size_of<T>() -> usize { - 4 - } -} diff --git a/src/lib.rs b/src/lib.rs index 8a7750acb0acac2090146b922fdefbee6c97d9be..3fddb3f504b0ff7ff527597d6c7a449a5effe940 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,13 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. //! libc - Raw FFI bindings to platforms' system libraries - #![crate_name = "libc"] #![crate_type = "rlib"] #![cfg_attr(not(feature = "rustc-dep-of-std"), deny(warnings))] #![allow(bad_style, overflowing_literals, improper_ctypes, unknown_lints)] -#![cfg_attr(cross_platform_docs, feature(no_core, lang_items, const_fn))] -#![cfg_attr(cross_platform_docs, no_core)] // Attributes needed when building as part of the standard library #![cfg_attr( feature = "rustc-dep-of-std", @@ -28,12 +25,11 @@ not(any( feature = "use_std", feature = "rustc-dep-of-std", - cross_platform_docs )), no_std )] -#[cfg(all(not(cross_platform_docs), feature = "use_std"))] +#[cfg(feature = "use_std")] extern crate std as core; #[macro_use] @@ -50,60 +46,49 @@ cfg_if! { } cfg_if! { - if #[cfg(not(cross_platform_docs))] { - cfg_if! { - if #[cfg(libc_priv_mod_use)] { - #[cfg(libc_core_cvoid)] - #[allow(unused_imports)] - use core::ffi; - #[allow(unused_imports)] - use core::fmt; - #[allow(unused_imports)] - use core::hash; - #[allow(unused_imports)] - use core::num; - #[allow(unused_imports)] - use core::mem; - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::clone::Clone; - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::marker::Copy; - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::option::Option; - } else { - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::fmt; - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::hash; - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::num; - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::mem; - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::clone::Clone; - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::marker::Copy; - #[doc(hidden)] - #[allow(unused_imports)] - pub use core::option::Option; - } - } - } -} - -cfg_if! { - if #[cfg(cross_platform_docs)] { - mod dox; - pub use self::dox::*; + if #[cfg(libc_priv_mod_use)] { + #[cfg(libc_core_cvoid)] + #[allow(unused_imports)] + use core::ffi; + #[allow(unused_imports)] + use core::fmt; + #[allow(unused_imports)] + use core::hash; + #[allow(unused_imports)] + use core::num; + #[allow(unused_imports)] + use core::mem; + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::clone::Clone; + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::marker::Copy; + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::option::Option; + } else { + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::fmt; + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::hash; + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::num; + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::mem; + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::clone::Clone; + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::marker::Copy; + #[doc(hidden)] + #[allow(unused_imports)] + pub use core::option::Option; } } diff --git a/src/macros.rs b/src/macros.rs index af7bbdd37bb94463cd11907371d0cfd78f9d12f2..c48ae8bc40b416a99a8b30dadb02bc0d54f044a6 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -124,16 +124,9 @@ macro_rules! f { $($body:stmt);* })*) => ($( #[inline] - #[cfg(not(cross_platform_docs))] pub unsafe extern fn $i($($arg: $argty),*) -> $ret { $($body);* } - - #[cfg(cross_platform_docs)] - #[allow(dead_code)] - pub unsafe extern fn $i($($arg: $argty),*) -> $ret { - loop {} - } )*) } diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index c4fc528439644fe487c72b88dd5873dc7b9deb9c..7c96ebcf0e669dced63f83b277780ff8fc95a227 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -31,23 +31,6 @@ s! { pub e_exit: u16 } - pub struct utmpx { - pub ut_name: [::c_char; 32], - pub ut_id: [::c_char; 4], - - pub ut_line: [::c_char; 32], - pub ut_host: [::c_char; 256], - - pub ut_unused: [u8; 16], - pub ut_session: u16, - pub ut_type: u16, - pub ut_pid: ::pid_t, - ut_exit: exit_status, - ut_ss: ::sockaddr_storage, - pub ut_tv: ::timeval, - pub ut_unused2: [u8; 16], - } - pub struct aiocb { pub aio_fildes: ::c_int, pub aio_offset: ::off_t, @@ -60,15 +43,6 @@ s! { _aio_err: ::c_int } - pub struct dirent { - pub d_fileno: ::ino_t, - pub d_namlen: u16, - pub d_type: u8, - __unused1: u8, - __unused2: u32, - pub d_name: [::c_char; 256], - } - pub struct uuid { pub time_low: u32, pub time_mid: u16, @@ -120,27 +94,6 @@ s! { pub f_uid_uuid: ::uuid_t, } - pub struct statfs { - pub f_bsize: ::c_long, - pub f_iosize: ::c_long, - pub f_blocks: ::c_long, - pub f_bfree: ::c_long, - pub f_bavail: ::c_long, - pub f_files: ::c_long, - pub f_ffree: ::c_long, - pub f_fsid: ::fsid_t, - pub f_owner: ::uid_t, - pub f_type: ::int32_t, - pub f_flags: ::int32_t, - pub f_syncwrites: ::c_long, - pub f_asyncwrites: ::c_long, - pub f_fstypename: [::c_char; 16], - pub f_mntonname: [::c_char; 90], - pub f_syncreads: ::c_long, - pub f_asyncreads: ::c_long, - pub f_mntfromname: [::c_char; 90], - } - pub struct stat { pub st_ino: ::ino_t, pub st_nlink: ::nlink_t, @@ -223,6 +176,58 @@ s! { } } +s_no_extra_traits! { + #[allow(missing_debug_implementations)] + pub struct utmpx { + pub ut_name: [::c_char; 32], + pub ut_id: [::c_char; 4], + + pub ut_line: [::c_char; 32], + pub ut_host: [::c_char; 256], + + pub ut_unused: [u8; 16], + pub ut_session: u16, + pub ut_type: u16, + pub ut_pid: ::pid_t, + ut_exit: exit_status, + ut_ss: ::sockaddr_storage, + pub ut_tv: ::timeval, + pub ut_unused2: [u8; 16], + } + + #[allow(missing_debug_implementations)] + pub struct dirent { + pub d_fileno: ::ino_t, + pub d_namlen: u16, + pub d_type: u8, + __unused1: u8, + __unused2: u32, + pub d_name: [::c_char; 256], + } + + #[allow(missing_debug_implementations)] + pub struct statfs { + pub f_bsize: ::c_long, + pub f_iosize: ::c_long, + pub f_blocks: ::c_long, + pub f_bfree: ::c_long, + pub f_bavail: ::c_long, + pub f_files: ::c_long, + pub f_ffree: ::c_long, + pub f_fsid: ::fsid_t, + pub f_owner: ::uid_t, + pub f_type: ::int32_t, + pub f_flags: ::int32_t, + pub f_syncwrites: ::c_long, + pub f_asyncwrites: ::c_long, + pub f_fstypename: [::c_char; 16], + pub f_mntonname: [::c_char; 90], + pub f_syncreads: ::c_long, + pub f_asyncreads: ::c_long, + pub f_mntfromname: [::c_char; 90], + } +} + pub const RAND_MAX: ::c_int = 0x7fff_ffff; pub const PTHREAD_STACK_MIN: ::size_t = 16384; pub const SIGSTKSZ: ::size_t = 40960; @@ -804,26 +809,28 @@ f! { } pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { - _CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) + length as usize + (_CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) + length as usize) + as ::c_uint } pub fn CMSG_NXTHDR(mhdr: *const ::msghdr, cmsg: *const ::cmsghdr) -> *mut ::cmsghdr { - let next = cmsg as usize + _CMSG_ALIGN((*cmsg).cmsg_len) + let next = cmsg as usize + _CMSG_ALIGN((*cmsg).cmsg_len as usize) + _CMSG_ALIGN(::mem::size_of::<::cmsghdr>()); let max = (*mhdr).msg_control as usize + (*mhdr).msg_controllen as usize; if next <= max { - (cmsg as usize + _CMSG_ALIGN((*cmsg).cmsg_len)) as *mut ::cmsghdr + (cmsg as usize + _CMSG_ALIGN((*cmsg).cmsg_len as usize)) + as *mut ::cmsghdr } else { 0 as *mut ::cmsghdr } } pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { - _CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) + - _CMSG_ALIGN(length as usize) + (_CMSG_ALIGN(::mem::size_of::<::cmsghdr>()) + + _CMSG_ALIGN(length as usize)) as ::c_uint } } diff --git a/src/unix/bsd/netbsdlike/mod.rs b/src/unix/bsd/netbsdlike/mod.rs index 7ba19931fd824439645149aaac1cdc0da2b311c0..c06d4793f902208c3ca6996c33ac00db9454bc15 100644 --- a/src/unix/bsd/netbsdlike/mod.rs +++ b/src/unix/bsd/netbsdlike/mod.rs @@ -595,56 +595,6 @@ pub const SF_APPEND: ::c_ulong = 0x00040000; pub const TIMER_ABSTIME: ::c_int = 1; -fn _ALIGN(p: usize) -> usize { - (p + _ALIGNBYTES) & !_ALIGNBYTES -} - -f! { - pub fn CMSG_DATA(cmsg: *const ::cmsghdr) -> *mut ::c_uchar { - (cmsg as *mut ::c_uchar) - .offset(_ALIGN(::mem::size_of::<::cmsghdr>()) as isize) - } - - pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { - _ALIGN(::mem::size_of::<::cmsghdr>()) as ::c_uint + length - } - - pub fn CMSG_NXTHDR(mhdr: *const ::msghdr, cmsg: *const ::cmsghdr) - -> *mut ::cmsghdr - { - if cmsg.is_null() { - return ::CMSG_FIRSTHDR(mhdr); - }; - let next = cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize) - + _ALIGN(::mem::size_of::<::cmsghdr>()); - let max = (*mhdr).msg_control as usize - + (*mhdr).msg_controllen as usize; - if next > max { - 0 as *mut ::cmsghdr - } else { - (cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize)) - as *mut ::cmsghdr - } - } - - pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { - (_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize)) - as ::c_uint - } - - pub fn WSTOPSIG(status: ::c_int) -> ::c_int { - status >> 8 - } - - pub fn WIFSIGNALED(status: ::c_int) -> bool { - (status & 0o177) != 0o177 && (status & 0o177) != 0 - } - - pub fn WIFSTOPPED(status: ::c_int) -> bool { - (status & 0o177) == 0o177 - } -} - #[link(name = "util")] extern { pub fn mincore(addr: *mut ::c_void, len: ::size_t, diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 1bc6743ac188aa0524711b1ddb5fc5b3cd8e193a..e1ba222bf7b7289d1c8c786ab333ae0a73c3a780 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -1060,10 +1060,58 @@ pub const SF_SNAPSHOT: ::c_ulong = 0x00200000; pub const SF_LOG: ::c_ulong = 0x00400000; pub const SF_SNAPINVAL: ::c_ulong = 0x00800000; -// dirfd() is a macro on netbsd to access -// the first field of the struct where dirp points to: -// http://cvsweb.netbsd.org/bsdweb.cgi/src/include/dirent.h?rev=1.36 +fn _ALIGN(p: usize) -> usize { + (p + _ALIGNBYTES) & !_ALIGNBYTES +} + f! { + pub fn CMSG_DATA(cmsg: *const ::cmsghdr) -> *mut ::c_uchar { + (cmsg as *mut ::c_uchar) + .offset(_ALIGN(::mem::size_of::<::cmsghdr>()) as isize) + } + + pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { + _ALIGN(::mem::size_of::<::cmsghdr>()) as ::c_uint + length + } + + pub fn CMSG_NXTHDR(mhdr: *const ::msghdr, cmsg: *const ::cmsghdr) + -> *mut ::cmsghdr + { + if cmsg.is_null() { + return ::CMSG_FIRSTHDR(mhdr); + }; + let next = cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize) + + _ALIGN(::mem::size_of::<::cmsghdr>()); + let max = (*mhdr).msg_control as usize + + (*mhdr).msg_controllen as usize; + if next > max { + 0 as *mut ::cmsghdr + } else { + (cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize)) + as *mut ::cmsghdr + } + } + + pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { + (_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize)) + as ::c_uint + } + + pub fn WSTOPSIG(status: ::c_int) -> ::c_int { + status >> 8 + } + + pub fn WIFSIGNALED(status: ::c_int) -> bool { + (status & 0o177) != 0o177 && (status & 0o177) != 0 + } + + pub fn WIFSTOPPED(status: ::c_int) -> bool { + (status & 0o177) == 0o177 + } + + // dirfd() is a macro on netbsd to access + // the first field of the struct where dirp points to: + // http://cvsweb.netbsd.org/bsdweb.cgi/src/include/dirent.h?rev=1.36 pub fn dirfd(dirp: *mut ::DIR) -> ::c_int { *(dirp as *const ::c_int) } diff --git a/src/unix/bsd/netbsdlike/openbsdlike/mod.rs b/src/unix/bsd/netbsdlike/openbsdlike/mod.rs index a003a0d0cea723a9c669f35fa5137aa4dcba0c02..843a5457ce1d7998bf7211944f0abdd920d096dc 100644 --- a/src/unix/bsd/netbsdlike/openbsdlike/mod.rs +++ b/src/unix/bsd/netbsdlike/openbsdlike/mod.rs @@ -242,8 +242,8 @@ cfg_if! { impl Eq for dirent {} - impl std::fmt::Debug for dirent { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + impl ::fmt::Debug for dirent { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { f.debug_struct("dirent") .field("d_fileno", &self.d_fileno) .field("d_off", &self.d_off) @@ -255,8 +255,8 @@ cfg_if! { } } - impl std::hash::Hash for dirent { - fn hash<H: std::hash::Hasher>(&self, state: &mut H) { + impl ::hash::Hash for dirent { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { self.d_fileno.hash(state); self.d_off.hash(state); self.d_reclen.hash(state); @@ -275,8 +275,8 @@ cfg_if! { impl Eq for sockaddr_storage {} - impl std::fmt::Debug for sockaddr_storage { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + impl ::fmt::Debug for sockaddr_storage { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { f.debug_struct("sockaddr_storage") .field("ss_len", &self.ss_len) .field("ss_family", &self.ss_family) @@ -284,8 +284,8 @@ cfg_if! { } } - impl std::hash::Hash for sockaddr_storage { - fn hash<H: std::hash::Hasher>(&self, state: &mut H) { + impl ::hash::Hash for sockaddr_storage { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { self.ss_len.hash(state); self.ss_family.hash(state); } @@ -302,8 +302,8 @@ cfg_if! { impl Eq for siginfo_t {} - impl std::fmt::Debug for siginfo_t { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + impl ::fmt::Debug for siginfo_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { f.debug_struct("siginfo_t") .field("si_signo", &self.si_signo) .field("si_code", &self.si_code) @@ -313,8 +313,8 @@ cfg_if! { } } - impl std::hash::Hash for siginfo_t { - fn hash<H: std::hash::Hasher>(&self, state: &mut H) { + impl ::hash::Hash for siginfo_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { self.si_signo.hash(state); self.si_code.hash(state); self.si_errno.hash(state); @@ -340,8 +340,8 @@ cfg_if! { impl Eq for lastlog {} - impl std::fmt::Debug for lastlog { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + impl ::fmt::Debug for lastlog { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { f.debug_struct("lastlog") .field("ll_time", &self.ll_time) // FIXME: .field("ll_line", &self.ll_line) @@ -350,8 +350,8 @@ cfg_if! { } } - impl std::hash::Hash for lastlog { - fn hash<H: std::hash::Hasher>(&self, state: &mut H) { + impl ::hash::Hash for lastlog { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { self.ll_time.hash(state); self.ll_line.hash(state); self.ll_host.hash(state); @@ -381,8 +381,8 @@ cfg_if! { impl Eq for utmp {} - impl std::fmt::Debug for utmp { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + impl ::fmt::Debug for utmp { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { f.debug_struct("utmp") // FIXME: .field("ut_line", &self.ut_line) // FIXME: .field("ut_name", &self.ut_name) @@ -392,8 +392,8 @@ cfg_if! { } } - impl std::hash::Hash for utmp { - fn hash<H: std::hash::Hasher>(&self, state: &mut H) { + impl ::hash::Hash for utmp { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { self.ut_line.hash(state); self.ut_name.hash(state); self.ut_host.hash(state); diff --git a/src/unix/bsd/netbsdlike/openbsdlike/openbsd/mod.rs b/src/unix/bsd/netbsdlike/openbsdlike/openbsd/mod.rs index 5c9eea1db4308b0263ac0dcae0fec73ec18e4cd3..69859cbb1a4242f664ca4e919ba30d5e8b949d9f 100644 --- a/src/unix/bsd/netbsdlike/openbsdlike/openbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/openbsdlike/openbsd/mod.rs @@ -157,16 +157,16 @@ cfg_if! { impl Eq for mount_info { } - impl std::fmt::Debug for mount_info { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + impl ::fmt::Debug for mount_info { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { f.debug_struct("mount_info") // FIXME: .field("align", &self.align) .finish() } } - impl std::hash::Hash for mount_info { - fn hash<H: std::hash::Hasher>(&self, state: &mut H) { + impl ::hash::Hash for mount_info { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { unsafe { self.align.hash(state) }; } } @@ -246,9 +246,9 @@ cfg_if! { impl Eq for statfs { } - impl std::fmt::Debug for statfs { - fn fmt(&self, f: &mut std::fmt::Formatter) - -> std::fmt::Result { + impl ::fmt::Debug for statfs { + fn fmt(&self, f: &mut ::fmt::Formatter) + -> ::fmt::Result { f.debug_struct("statfs") .field("f_flags", &self.f_flags) .field("f_bsize", &self.f_bsize) @@ -276,8 +276,8 @@ cfg_if! { } } - impl std::hash::Hash for statfs { - fn hash<H: std::hash::Hasher>(&self, state: &mut H) { + impl ::hash::Hash for statfs { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { self.f_flags.hash(state); self.f_bsize.hash(state); self.f_iosize.hash(state); @@ -305,6 +305,7 @@ cfg_if! { } } } +} //https://github.com/openbsd/src/blob/master/sys/sys/mount.h pub const ISOFSMNT_NORRIP: ::c_int = 0x1; // disable Rock Ridge Ext @@ -391,6 +392,56 @@ pub const SIGSTKSZ : ::size_t = 28672; pub const PT_FIRSTMACH: ::c_int = 32; +fn _ALIGN(p: usize) -> usize { + (p + _ALIGNBYTES) & !_ALIGNBYTES +} + +f! { + pub fn CMSG_DATA(cmsg: *const ::cmsghdr) -> *mut ::c_uchar { + (cmsg as *mut ::c_uchar) + .offset(_ALIGN(::mem::size_of::<::cmsghdr>()) as isize) + } + + pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint { + _ALIGN(::mem::size_of::<::cmsghdr>()) as ::c_uint + length + } + + pub fn CMSG_NXTHDR(mhdr: *const ::msghdr, cmsg: *const ::cmsghdr) + -> *mut ::cmsghdr + { + if cmsg.is_null() { + return ::CMSG_FIRSTHDR(mhdr); + }; + let next = cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize) + + _ALIGN(::mem::size_of::<::cmsghdr>()); + let max = (*mhdr).msg_control as usize + + (*mhdr).msg_controllen as usize; + if next > max { + 0 as *mut ::cmsghdr + } else { + (cmsg as usize + _ALIGN((*cmsg).cmsg_len as usize)) + as *mut ::cmsghdr + } + } + + pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint { + (_ALIGN(::mem::size_of::<::cmsghdr>()) + _ALIGN(length as usize)) + as ::c_uint + } + + pub fn WSTOPSIG(status: ::c_int) -> ::c_int { + status >> 8 + } + + pub fn WIFSIGNALED(status: ::c_int) -> bool { + (status & 0o177) != 0o177 && (status & 0o177) != 0 + } + + pub fn WIFSTOPPED(status: ::c_int) -> bool { + (status & 0o177) == 0o177 + } +} + extern { pub fn accept4(s: ::c_int, addr: *mut ::sockaddr, addrlen: *mut ::socklen_t, flags: ::c_int) -> ::c_int; diff --git a/src/unix/haiku/mod.rs b/src/unix/haiku/mod.rs index 4d2082fa2ccccf623a21829805d44f9b828e9a3e..d73967781bb04500c50835eece4a0f8f8d737e4e 100644 --- a/src/unix/haiku/mod.rs +++ b/src/unix/haiku/mod.rs @@ -69,20 +69,6 @@ s! { pub sin6_scope_id: u32, } - pub struct sockaddr_un { - pub sun_len: u8, - pub sun_family: sa_family_t, - pub sun_path: [::c_char; 126] - } - - pub struct sockaddr_storage { - pub ss_len: u8, - pub ss_family: sa_family_t, - __ss_pad1: [u8; 6], - __ss_pad2: u64, - __ss_pad3: [u8; 112], - } - pub struct addrinfo { pub ai_flags: ::c_int, pub ai_family: ::c_int, @@ -211,15 +197,6 @@ s! { pub st_blocks: blkcnt_t, } - pub struct dirent { - pub d_dev: dev_t, - pub d_pdev: dev_t, - pub d_ino: ino_t, - pub d_pino: i64, - pub d_reclen: ::c_ushort, - pub d_name: [::c_char; 1024], // Max length is _POSIX_PATH_MAX - } - pub struct glob_t { pub gl_pathc: ::size_t, __unused1: ::size_t, @@ -331,6 +308,32 @@ s! { } } +s_no_extra_traits! { + #[allow(missing_debug_implementations)] + pub struct sockaddr_un { + pub sun_len: u8, + pub sun_family: sa_family_t, + pub sun_path: [::c_char; 126] + } + #[allow(missing_debug_implementations)] + pub struct sockaddr_storage { + pub ss_len: u8, + pub ss_family: sa_family_t, + __ss_pad1: [u8; 6], + __ss_pad2: u64, + __ss_pad3: [u8; 112], + } + #[allow(missing_debug_implementations)] + pub struct dirent { + pub d_dev: dev_t, + pub d_pdev: dev_t, + pub d_ino: ino_t, + pub d_pino: i64, + pub d_reclen: ::c_ushort, + pub d_name: [::c_char; 1024], // Max length is _POSIX_PATH_MAX + } +} + // intentionally not public, only used for fd_set cfg_if! { if #[cfg(target_pointer_width = "32")] { diff --git a/src/unix/mod.rs b/src/unix/mod.rs index cb0862f55ad6387554d8879bb599201f4ba8b76d..057a93bd75266046223ff1c681620c95987d32e0 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -301,9 +301,7 @@ pub const ATF_PUBL: ::c_int = 0x08; pub const ATF_USETRAILERS: ::c_int = 0x10; cfg_if! { - if #[cfg(cross_platform_docs)] { - // on dox builds don't pull in anything - } else if #[cfg(target_os = "l4re")] { + if #[cfg(target_os = "l4re")] { // required libraries for L4Re are linked externally, ATM } else if #[cfg(feature = "use_std")] { // cargo build, don't pull in anything extra as the libstd dep