This commit is contained in:
Björn Quentin 2025-01-06 15:57:20 +01:00
parent b462a19bd4
commit 32adedb63b

View File

@ -23,16 +23,17 @@ unsafe extern "C" fn fclose(stream: *const ()) -> i32 {
// We cannot just use the ROM function since it needs to allocate memory
#[no_mangle]
unsafe extern "C" fn strdup(str: *const i8) -> *const u8 {
unsafe extern "C" fn strdup(str: *const core::ffi::c_char) -> *const core::ffi::c_char {
trace!("strdup {:?}", str);
unsafe {
let s = core::ffi::CStr::from_ptr(str);
let s = s.to_str().unwrap();
let p = malloc(s.len() + 1);
core::ptr::copy_nonoverlapping(str, p as *mut i8, s.len() + 1);
p as *const u8
let len = s.count_bytes() + 1;
let p = malloc(len);
if !p.is_null() {
core::ptr::copy_nonoverlapping(str, p as *mut i8, len);
}
p.cast()
}
}