summaryrefslogtreecommitdiff
path: root/nix-test/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'nix-test/src/lib.rs')
-rw-r--r--nix-test/src/lib.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/nix-test/src/lib.rs b/nix-test/src/lib.rs
new file mode 100644
index 00000000..a8be2feb
--- /dev/null
+++ b/nix-test/src/lib.rs
@@ -0,0 +1,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);
+ }
+ }
+}