Skip to content
Snippets Groups Projects
Commit 614b2f51 authored by Nagy Tibor's avatar Nagy Tibor
Browse files

Make assert more hygienic

parent baddbb98
No related branches found
No related tags found
1 merge request!166Make assert more hygienic
#ifndef _ASSERT_H
#define _ASSERT_H
#ifndef _BITS_ASSERT_H
#define _BITS_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(); \
}
__assert(__func__, __FILE__, __LINE__, #cond); \
}
#endif
#endif
sys_includes = ["bits/assert.h"]
include_guard = "_ASSERT_H"
language = "C"
style = "Tag"
[enum]
prefix_with_name = true
//! 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();
}
pub mod aio;
pub mod arpa_inet;
pub mod assert;
pub mod ctype;
pub mod dirent;
pub mod errno;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment