Merge branch 'monetary-regex-cleanup' into 'master'

monetary net_if and regex cleanup

See merge request redox-os/relibc!1034
This commit is contained in:
Jeremy Soller
2026-02-23 08:36:51 -07:00
3 changed files with 19 additions and 23 deletions
+11 -11
View File
@@ -13,7 +13,7 @@ use libm::{fabs, pow, round, trunc};
///
/// Returns:
/// - The number of characters written (excluding the null terminator), or -1 if
/// an error occurs (e.g., invalid input, buffer overflow)
/// an error occurs (e.g., invalid input, buffer overflow)
pub unsafe extern "C" fn strfmon(
s: *mut c_char, // Output buffer
maxsize: usize, // Maximum size of the buffer
@@ -32,7 +32,7 @@ pub unsafe extern "C" fn strfmon(
};
// Create a mutable slice for the output buffer
let buffer = unsafe { slice::from_raw_parts_mut(s as *mut u8, maxsize) };
let buffer = unsafe { slice::from_raw_parts_mut(s.cast::<u8>(), maxsize) };
let mut pos = 0;
let mut format_chars = format_str.chars().peekable();
@@ -302,15 +302,15 @@ fn format_monetary(
// 14) checks if the user specified a total field width
// - if the final result is shorter, we padd it
// - if `left_justify` is true, padd on the right otherwise padd on the left
if let Some(width) = flags.field_width {
if result.len() < width {
let padding = " ".repeat(width - result.len());
result = if flags.left_justify {
result + &padding
} else {
padding + &result
};
}
if let Some(width) = flags.field_width
&& result.len() < width
{
let padding = " ".repeat(width - result.len());
result = if flags.left_justify {
result + &padding
} else {
padding + &result
};
}
// 15) write the final string to the buffer
+2 -2
View File
@@ -66,7 +66,7 @@ pub unsafe extern "C" fn if_indextoname(idx: c_uint, buf: *mut c_char) -> *const
/// The end of the list is determined by an if_nameindex struct having if_index 0 and if_name NULL
#[unsafe(no_mangle)]
pub unsafe extern "C" fn if_nameindex() -> *const if_nameindex {
&INTERFACES[0] as *const if_nameindex
core::ptr::from_ref::<if_nameindex>(&INTERFACES[0])
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/if_nametoindex.html>.
@@ -76,7 +76,7 @@ pub unsafe extern "C" fn if_nameindex() -> *const if_nameindex {
/// An invalid name string will return an index of 0
#[unsafe(no_mangle)]
pub unsafe extern "C" fn if_nametoindex(name: *const c_char) -> c_uint {
if name == null::<c_char>() {
if name.is_null() {
return 0;
}
let name = unsafe { CStr::from_ptr(name).to_str().unwrap_or("") };
+6 -10
View File
@@ -56,7 +56,7 @@ pub const REG_BADRPT: c_int = 14;
#[unsafe(no_mangle)]
#[linkage = "weak"] // redefined in GIT
pub unsafe extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags: c_int) -> c_int {
let pat = unsafe { slice::from_raw_parts(pat as *const u8, strlen(pat)) };
let pat = unsafe { slice::from_raw_parts(pat.cast::<u8>(), strlen(pat)) };
let res = PosixRegexBuilder::new(pat)
.with_default_classes()
.extended(cflags & REG_EXTENDED == REG_EXTENDED)
@@ -67,7 +67,7 @@ pub unsafe extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags:
let re_nsub = PosixRegex::new(Cow::Borrowed(&branches)).count_groups();
unsafe {
*out = regex_t {
ptr: Box::into_raw(Box::new(branches)) as *mut c_void,
ptr: Box::into_raw(Box::new(branches)).cast::<c_void>(),
cflags,
re_nsub,
@@ -109,10 +109,10 @@ pub unsafe extern "C" fn regexec(
// because why not?
let flags = regex.cflags | eflags;
let input = unsafe { slice::from_raw_parts(input as *const u8, strlen(input)) };
let branches = unsafe { &*(regex.ptr as *mut Tree) };
let input = unsafe { slice::from_raw_parts(input.cast::<u8>(), strlen(input)) };
let branches = unsafe { &*(regex.ptr.cast::<Tree>()) };
let matches = PosixRegex::new(Cow::Borrowed(&branches))
let matches = PosixRegex::new(Cow::Borrowed(branches))
.case_insensitive(flags & REG_ICASE == REG_ICASE)
.newline(flags & REG_NEWLINE == REG_NEWLINE)
.no_start(flags & REG_NOTBOL == REG_NOTBOL)
@@ -165,11 +165,7 @@ pub extern "C" fn regerror(
};
unsafe {
ptr::copy_nonoverlapping(
string.as_ptr(),
out as *mut u8,
string.len().min(max as usize),
);
ptr::copy_nonoverlapping(string.as_ptr(), out.cast::<u8>(), string.len().min(max));
}
string.len()