blob: a8be2feb6322ac673b1d2ab1877552480ff26a93 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#![feature(libc, std_misc)]
extern crate libc;
use std::ffi::CString;
use libc::{c_int};
mod ffi {
use libc::{c_int, c_char};
#[link(name = "nixtest", kind = "static")]
extern {
pub fn assert_errno_eq(errno: *const c_char) -> c_int;
}
}
pub fn assert_errno_eq(err: &str, val: c_int) {
unsafe {
let name = CString::from_slice(err.as_bytes());
let actual = ffi::assert_errno_eq(name.as_ptr());
assert!(actual > 0);
if val != actual {
panic!("incorrect value for errno {}; got={}; expected={}",
err, val, actual);
}
}
}
|