assert.h: full impl
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
#ifndef _ASSERT_H
|
||||
#define _ASSERT_H 1
|
||||
|
||||
#define assert(x) \
|
||||
do { \
|
||||
if (!(x)) { \
|
||||
__assert_fail(__FILE__, __LINE__, #x); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
extern _Noreturn void __assert_fail(const char *file, int line, const char *message);
|
||||
|
||||
#endif
|
||||
+1
-1
@@ -16,7 +16,7 @@ pub mod unistd;
|
||||
Impl Check Name
|
||||
MAYBE aio.h - asynchronous input and output
|
||||
OSSUP arpa/inet.h - definitions for internet operations
|
||||
----- assert.h - verify program assertion
|
||||
+++++ assert.h - verify program assertion
|
||||
----- complex.h - complex arithmetic
|
||||
----- cpio.h - cpio archive values
|
||||
----- ctype.h - character types
|
||||
|
||||
+21
-2
@@ -12,13 +12,14 @@
|
||||
#![allow(internal_features)]
|
||||
#![no_std]
|
||||
|
||||
use core::ffi::{c_char, c_int};
|
||||
use core::ffi::{c_char, c_int, CStr};
|
||||
|
||||
use alloc::{ffi::CString, vec::Vec};
|
||||
use header::unistd::environ;
|
||||
use util::Nullable;
|
||||
use yggdrasil_rt::process::{ExitCode, ProgramArgumentInner};
|
||||
|
||||
use crate::header::stdio;
|
||||
use crate::header::stdio::{self, stderr};
|
||||
|
||||
extern crate alloc;
|
||||
extern crate yggdrasil_rt;
|
||||
@@ -60,3 +61,21 @@ fn panic_handler(pi: &core::panic::PanicInfo) -> ! {
|
||||
yggdrasil_rt::debug_trace!("--- END PANIC ---");
|
||||
process::exit(ExitCode::Exited(1));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn __assert_fail(file: *const c_char, line: c_int, expr: *const c_char) -> ! {
|
||||
use core::fmt::Write;
|
||||
|
||||
let err = stderr.as_mut().unwrap();
|
||||
|
||||
file.ensure();
|
||||
expr.ensure();
|
||||
|
||||
let file = CStr::from_ptr(file).to_str().unwrap();
|
||||
let expr = CStr::from_ptr(expr).to_str().unwrap();
|
||||
|
||||
// These should not be NULL, but check nevertheless
|
||||
writeln!(err, "Assertion failed: {:?} at {}:{}", expr, file, line);
|
||||
|
||||
panic!("TODO: abort()");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user