mirror of
https://github.com/Noratrieb/libuwuc.git
synced 2026-01-14 19:55:07 +01:00
implement more things
This commit is contained in:
parent
119d0f1443
commit
9e2cf38cd5
11 changed files with 177 additions and 12 deletions
|
|
@ -8,6 +8,7 @@ mod rt;
|
|||
mod stdio;
|
||||
mod stdlib;
|
||||
mod string;
|
||||
mod unistd;
|
||||
|
||||
// libcore seems to require this symbol, even though it's unused.
|
||||
#[no_mangle]
|
||||
|
|
|
|||
|
|
@ -2,9 +2,13 @@ use core::ffi::{c_int, c_long};
|
|||
|
||||
use libuwuc::{error::IntoOkOrErrno, utils::SharedThinCstr};
|
||||
|
||||
// Allocation functions
|
||||
|
||||
const MAX_ALIGN: usize = 16;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn malloc(size: usize) -> *mut u8 {
|
||||
libuwuc::alloc::malloc_zeroed(size, 16)
|
||||
libuwuc::alloc::malloc_zeroed(size, MAX_ALIGN)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
|
@ -13,10 +17,22 @@ pub unsafe extern "C" fn free(ptr: *mut u8) {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn exit(code: i32) -> ! {
|
||||
libuwuc::start::sys_exit(code as i64 as _)
|
||||
pub unsafe extern "C" fn calloc(nmemb: usize, size: usize) -> *mut u8 {
|
||||
libuwuc::alloc::malloc_zeroed_array(nmemb, size, MAX_ALIGN)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn realloc(ptr: *mut u8, size: usize) -> *mut u8 {
|
||||
libuwuc::alloc::realloc(ptr, size, MAX_ALIGN)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn reallocarray(ptr: *mut u8, nmemb: usize, size: usize) -> *mut u8 {
|
||||
libuwuc::alloc::reallocarray(ptr, nmemb, size, MAX_ALIGN)
|
||||
}
|
||||
|
||||
// Integer parsing functions
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn strtol(nptr: *const u8, endptr: *mut *const u8, base: c_int) -> c_long {
|
||||
let str = SharedThinCstr::from_raw(nptr);
|
||||
|
|
@ -33,9 +49,16 @@ pub unsafe extern "C" fn strtoll(nptr: *const u8, endptr: *mut *const u8, base:
|
|||
strtol(nptr, endptr, base)
|
||||
}
|
||||
|
||||
// Other functions
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn getenv(name: *const u8) -> *const u8 {
|
||||
libuwuc::env::getenv(SharedThinCstr::from_raw(name))
|
||||
.map(SharedThinCstr::as_raw)
|
||||
.unwrap_or(core::ptr::null())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn exit(code: i32) -> ! {
|
||||
libuwuc::start::sys_exit(code as i64 as _)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use libuwuc::error::Error;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memset(ptr: *mut u8, constant: u8, len: usize) {
|
||||
libuwuc::mem::memset(ptr, constant, len)
|
||||
|
|
@ -8,6 +10,11 @@ pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, size: usize) -> *
|
|||
libuwuc::mem::memcpy(dest, src, size)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memmove(dest: *mut u8, src: *const u8, size: usize) -> *mut u8 {
|
||||
libuwuc::mem::memmove(dest, src, size)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memcmp(s1: *const u8, s2: *const u8, size: usize) -> i32 {
|
||||
libuwuc::mem::memcmp(s1, s2, size)
|
||||
|
|
@ -22,3 +29,10 @@ pub unsafe extern "C" fn bcmp(s1: *const u8, s2: *const u8, size: usize) -> i32
|
|||
pub unsafe extern "C" fn strlen(s: *const u8) -> usize {
|
||||
libuwuc::mem::strlen(s)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn strerror(errnum: Error) -> *const u8 {
|
||||
libuwuc::error::strerror(errnum)
|
||||
.map(str::as_ptr)
|
||||
.unwrap_or(core::ptr::null())
|
||||
}
|
||||
|
|
|
|||
16
rawc/src/unistd.rs
Normal file
16
rawc/src/unistd.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
use libuwuc::error::IntoOkOrErrno;
|
||||
use libuwuc::io::fd::Fd;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn read(fd: Fd, buf: *mut u8, count: usize) -> isize {
|
||||
libuwuc::io::sys_read(fd, core::slice::from_raw_parts_mut(buf, count))
|
||||
.map(|n| n as isize)
|
||||
.into_ok_or_errno()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn write(fd: Fd, buf: *const u8, count: usize) -> isize {
|
||||
libuwuc::io::sys_write(fd, core::slice::from_raw_parts(buf, count))
|
||||
.map(|n| n as isize)
|
||||
.into_ok_or_errno()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue