Merge branch 'langinfo-libgen-cleanup' into 'master'
langinfo and libgen cleanup See merge request redox-os/relibc!1031
This commit is contained in:
@@ -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>.
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user