diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2017-12-08 14:44:02 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2017-12-08 14:44:02 +0000 |
commit | 7eaa20810a656158e4d57b792c58481f10987788 (patch) | |
tree | 0d2611e909d5eaa301211bdd0cb321ac57852d92 /nix-test/src/lib.rs | |
parent | d96518cf1b1877f1d8445e3e0e878fd25fbc822c (diff) | |
parent | a79d228de73141f9e816d4f23ebd0c8c4ed37f6f (diff) | |
download | nix-7eaa20810a656158e4d57b792c58481f10987788.zip |
Merge #807
807: Switch to libc definitons of errno constants r=Susurrus a=Susurrus
Still need to do OpenBSD and NetBSD. Primary goal with this first pass is to see what doesn't exist properly in `libc`.
Closes #487.
Diffstat (limited to 'nix-test/src/lib.rs')
-rw-r--r-- | nix-test/src/lib.rs | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/nix-test/src/lib.rs b/nix-test/src/lib.rs deleted file mode 100644 index cfe7b798..00000000 --- a/nix-test/src/lib.rs +++ /dev/null @@ -1,61 +0,0 @@ -extern crate libc; - -use std::fmt; -use std::ffi::CString; -use libc::{c_int, c_char}; - -mod ffi { - use libc::{c_int, c_char, size_t}; - - #[link(name = "nixtest", kind = "static")] - extern { - pub fn get_int_const(errno: *const c_char) -> c_int; - pub fn size_of(ty: *const c_char) -> size_t; - } -} - -pub fn assert_const_eq<T: GetConst>(name: &str, actual: T) { - unsafe { - let cstr = CString::new(name).unwrap(); - let expect = GetConst::get_const(cstr.as_ptr()); - - if actual != expect { - panic!("incorrect value for errno {}; expect={}; actual={}", - name, expect, actual); - } - } -} - -pub fn assert_size_of<T>(name: &str) { - use std::mem; - - unsafe { - let cstr = CString::new(name).unwrap(); - let expect = ffi::size_of(cstr.as_ptr()) as usize; - - assert!(expect > 0, "undefined type {}", name); - - if mem::size_of::<T>() != expect { - panic!("incorrectly sized type; expect={}; actual={}", - expect, mem::size_of::<T>()); - } - } -} - -pub use ffi::get_int_const; - -pub trait GetConst : PartialEq<Self> + fmt::Display { - unsafe fn get_const(name: *const c_char) -> Self; -} - -impl GetConst for c_int { - unsafe fn get_const(name: *const c_char) -> c_int { - ffi::get_int_const(name) - } -} - -impl GetConst for u32 { - unsafe fn get_const(name: *const c_char) -> u32 { - ffi::get_int_const(name) as u32 - } -} |