diff --git a/include/assert.h b/include/assert.h deleted file mode 100644 index 1a40206214bc81c7e103bbda7c2df8db6ff3c6e7..0000000000000000000000000000000000000000 --- a/include/assert.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _ASSERT_H -#define _ASSERT_H - -#ifdef NDEBUG -# define assert(cond) -#else -# include <stdio.h> -# define assert(cond) if (!(cond)) { \ - fprintf(stderr, "%s: %s:%d: Assertion `%s` failed.\n", __func__, __FILE__, __LINE__, #cond); \ - abort(); \ - } -#endif - -#endif diff --git a/include/bits/assert.h b/include/bits/assert.h new file mode 100644 index 0000000000000000000000000000000000000000..3a8c1b0017ce662ce62a3405138b6a967b46c4ae --- /dev/null +++ b/include/bits/assert.h @@ -0,0 +1,12 @@ +#ifndef _BITS_ASSERT_H +#define _BITS_ASSERT_H + +#ifdef NDEBUG +# define assert(cond) +#else +# define assert(cond) if (!(cond)) { \ + __assert(__func__, __FILE__, __LINE__, #cond); \ + } +#endif + +#endif diff --git a/src/header/assert/cbindgen.toml b/src/header/assert/cbindgen.toml new file mode 100644 index 0000000000000000000000000000000000000000..8eeb4d6d155f5be3998348bf54bf97e5e40bb446 --- /dev/null +++ b/src/header/assert/cbindgen.toml @@ -0,0 +1,7 @@ +sys_includes = ["bits/assert.h"] +include_guard = "_ASSERT_H" +language = "C" +style = "Tag" + +[enum] +prefix_with_name = true diff --git a/src/header/assert/mod.rs b/src/header/assert/mod.rs new file mode 100644 index 0000000000000000000000000000000000000000..838050f9ac752c4399d24213372f5aa8ba196b76 --- /dev/null +++ b/src/header/assert/mod.rs @@ -0,0 +1,17 @@ +//! assert implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/assert.h.html + +use c_str::CStr; +use core::fmt::Write; +use header::{stdio, stdlib}; +use platform; +use platform::types::*; + +#[no_mangle] +pub unsafe extern "C" fn __assert(func: *const c_char, file: *const c_char, line: c_int, cond: *const c_char) { + let func = CStr::from_ptr(func).to_str().unwrap(); + let file = CStr::from_ptr(file).to_str().unwrap(); + let cond = CStr::from_ptr(cond).to_str().unwrap(); + + write!(*stdio::stderr, "{}: {}:{}: Assertion `{}` failed.\n", func, file, line, cond).unwrap(); + stdlib::abort(); +} diff --git a/src/header/mod.rs b/src/header/mod.rs index c733f05d1d710e9a4738077e835d03f9881206cb..08cf34c826c427bd42e78374aa5d2d592dde6986 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -1,5 +1,6 @@ pub mod aio; pub mod arpa_inet; +pub mod assert; pub mod ctype; pub mod dirent; pub mod errno;