langinfo and libgen cleanup

This commit is contained in:
auronandace
2026-02-22 22:18:03 +00:00
parent 0430eb7426
commit 4ecce16dc4
2 changed files with 8 additions and 8 deletions
+3 -3
View File
@@ -202,13 +202,13 @@ pub const ABALTMON_12: nl_item = 80;
pub unsafe extern "C" fn nl_langinfo(item: nl_item) -> *mut c_char {
// Validate the item and perform the lookup
let ptr = if (item as usize) < STRING_TABLE.len() {
STRING_TABLE[item as usize].as_ptr() as *const c_char
STRING_TABLE[item as usize].as_ptr().cast::<c_char>()
} else {
// Return a pointer to an empty string if the item is invalid
b"\0".as_ptr() as *const c_char
c"".as_ptr().cast::<c_char>()
};
// Mutable pointer is required (unsafe!)
ptr as *mut c_char
ptr.cast_mut()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/nl_langinfo_l.html>.
+5 -5
View File
@@ -10,14 +10,14 @@ use crate::header::string::strlen;
#[unsafe(no_mangle)]
pub unsafe extern "C" fn basename(str: *mut c_char) -> *mut c_char {
if str.is_null() || unsafe { strlen(str) == 0 } {
return ".\0".as_ptr() as *mut c_char;
return c".".as_ptr().cast_mut();
}
let mut end = unsafe { strlen(str) as isize - 1 };
while end >= 0 && unsafe { *str.offset(end) == b'/' as c_char } {
end -= 1;
}
if end == -1 {
return "/\0".as_ptr() as *mut c_char;
return c"/".as_ptr().cast_mut();
}
let mut begin = end;
while begin >= 0 && unsafe { *str.offset(begin) != b'/' as c_char } {
@@ -25,7 +25,7 @@ pub unsafe extern "C" fn basename(str: *mut c_char) -> *mut c_char {
}
unsafe {
*str.offset(end + 1) = 0;
str.offset(begin + 1) as *mut c_char
str.offset(begin + 1).cast::<c_char>()
}
}
@@ -33,7 +33,7 @@ pub unsafe extern "C" fn basename(str: *mut c_char) -> *mut c_char {
#[unsafe(no_mangle)]
pub unsafe extern "C" fn dirname(str: *mut c_char) -> *mut c_char {
if str.is_null() || unsafe { strlen(str) == 0 } {
return ".\0".as_ptr() as *mut c_char;
return c".".as_ptr().cast_mut();
}
let mut end = unsafe { strlen(str) as isize - 1 };
while end > 0 && unsafe { *str.offset(end) == b'/' as c_char } {
@@ -46,7 +46,7 @@ pub unsafe extern "C" fn dirname(str: *mut c_char) -> *mut c_char {
end -= 1;
}
if end == -1 {
return ".\0".as_ptr() as *mut c_char;
return c".".as_ptr().cast_mut();
}
unsafe {
*str.offset(end + 1) = 0;