blob: 7fb6efb7e26581aa0704dfb8b530311e9e7d99f5 [file] [log] [blame]
Alex Crichtone8606192015-09-10 20:19:44 -07001#![allow(bad_style, unused_imports)]
Alex Crichton0df7c102015-09-10 16:35:37 -07002
Alex Crichton8e5f0cd2015-09-09 22:46:19 -07003extern crate libc;
4extern crate libc_test;
5
Alex Crichtonc8b895c2015-09-10 13:24:15 -07006use std::any::{Any, TypeId};
Alex Crichton16083062015-09-09 22:59:24 -07007use std::mem;
8
Alex Crichtona9adfbf2015-09-09 23:21:27 -07009use libc::*;
Alex Crichton22378822015-09-10 19:59:23 -070010#[cfg(unix)] use libc::types::os::common::bsd43::*;
11#[cfg(unix)] use libc::funcs::bsd44::*;
12#[cfg(unix)] use libc::funcs::posix01::mman::*;
13#[cfg(unix)] use libc::funcs::posix01::glob::*;
14#[cfg(unix)] use libc::funcs::posix01::signal::*;
15#[cfg(unix)] use libc::funcs::posix88::signal::*;
Alex Crichtone8606192015-09-10 20:19:44 -070016#[cfg(target_os = "macos")] use libc::funcs::extra::*;
Alex Crichtona9adfbf2015-09-09 23:21:27 -070017
Alex Crichton0df7c102015-09-10 16:35:37 -070018trait Pretty {
19 fn pretty(&self) -> String;
20}
21
22impl<T> Pretty for *const T {
23 fn pretty(&self) -> String { format!("{:?}", self) }
24}
25impl<T> Pretty for *mut T {
26 fn pretty(&self) -> String { format!("{:?}", self) }
27}
28macro_rules! p {
29 ($($i:ident)*) => ($(
30 impl Pretty for $i {
31 fn pretty(&self) -> String { format!("{} ({:#x})", self, self) }
32 }
33 )*)
34}
35p! { i8 i16 i32 i64 u8 u16 u32 u64 usize isize }
36
37fn same<T: Eq + Pretty>(rust: T, c: T, attr: &str) {
Alex Crichton3e5155b2015-09-09 23:46:19 -070038 if rust != c {
Alex Crichton0df7c102015-09-10 16:35:37 -070039 panic!("bad {}: rust: {} != c {}", attr, rust.pretty(), c.pretty());
Alex Crichton3e5155b2015-09-09 23:46:19 -070040 }
41}
42
Alex Crichtonc8b895c2015-09-10 13:24:15 -070043fn align<T: Any>() -> u64 {
44 // TODO: apparently these three types have less alignment in Rust on x86
45 // than they do in C this difference should.. probably be reconciled.
46 //
47 // Perhaps #27195?
48 if cfg!(target_pointer_width = "32") {
49 if TypeId::of::<T>() == TypeId::of::<f64>() ||
50 TypeId::of::<T>() == TypeId::of::<i64>() ||
51 TypeId::of::<T>() == TypeId::of::<u64>() {
52 return 8
53 }
54 }
55 mem::align_of::<T>() as u64
56}
57
Alex Crichton3e5155b2015-09-09 23:46:19 -070058macro_rules! offset_of {
59 ($ty:ident, $field:ident) => (
60 (&((*(0 as *const $ty)).$field)) as *const _ as u64
61 )
62}
63
Alex Crichton8e5f0cd2015-09-09 22:46:19 -070064#[cfg(test)]
65include!(concat!(env!("OUT_DIR"), "/all.rs"));