the big error refactor

This commit is contained in:
nora 2023-10-03 21:39:32 +02:00
parent 5057c0f977
commit 3829dddcea
19 changed files with 1027 additions and 456 deletions

View file

@ -26,5 +26,5 @@ fn handler(arg: &core::panic::PanicInfo) -> ! {
if let Some(loc) = arg.location() {
libuwuc::io::println!(" at {}:{}:{}", loc.file(), loc.line(), loc.column());
}
libuwuc::start::exit(1);
libuwuc::start::sys_exit(1);
}

View file

@ -1,9 +1,9 @@
use core::ffi::{c_char, c_int};
use libuwuc::{
io::{stream::FileStream, traits::WriteCounter, STDERR, STDIN, STDOUT},
error::IntoOkOrErrno,
io::{fd::Fd, stream::FileStream, traits::WriteCounter, STDERR, STDIN, STDOUT},
utils::SharedThinCstr,
error::IntoOkOrErrno
};
#[no_mangle]
@ -11,6 +11,13 @@ pub unsafe extern "C" fn puts(s: *const c_char) -> i32 {
libuwuc::io::puts(s)
}
// RAW FD:
#[no_mangle]
pub unsafe extern "C" fn open(path: SharedThinCstr, flags: i32) -> Fd {
libuwuc::io::fd::open(path, flags).into_ok_or_errno()
}
// PRINTF:
#[no_mangle]
@ -79,6 +86,14 @@ pub static stdout: &FileStream = &FileStream::from_raw_fd(STDOUT);
#[no_mangle]
pub static stderr: &FileStream = &FileStream::from_raw_fd(STDERR);
#[no_mangle]
pub unsafe extern "C" fn fopen<'a>(
pathname: SharedThinCstr,
mode: SharedThinCstr,
) -> Option<&'a FileStream> {
todo!()
}
#[no_mangle]
pub unsafe extern "C" fn fgetc(_stream: *mut FileStream) -> c_int {
todo!()

View file

@ -1,6 +1,6 @@
use core::ffi::{c_int, c_long};
use libuwuc::utils::SharedThinCstr;
use libuwuc::{error::IntoOkOrErrno, utils::SharedThinCstr};
#[no_mangle]
pub unsafe extern "C" fn malloc(size: usize) -> *mut u8 {
@ -14,7 +14,7 @@ pub unsafe extern "C" fn free(ptr: *mut u8) {
#[no_mangle]
pub unsafe extern "C" fn exit(code: i32) -> ! {
libuwuc::start::exit(code as i64 as _)
libuwuc::start::sys_exit(code as i64 as _)
}
#[no_mangle]
@ -25,6 +25,7 @@ pub unsafe extern "C" fn strtol(nptr: *const u8, endptr: *mut *const u8, base: c
core::mem::transmute::<*mut *const u8, Option<&mut Option<SharedThinCstr<'_>>>>(endptr),
base,
)
.into_ok_or_errno()
}
#[no_mangle]