Merge branch 'glob-cleanup' into 'master'

casting and clarity cleanups in glob

See merge request redox-os/relibc!1017
This commit is contained in:
Jeremy Soller
2026-02-19 06:35:11 -07:00
2 changed files with 18 additions and 18 deletions
+3 -3
View File
@@ -77,7 +77,7 @@ pub const EI_MAG2: usize = 2;
pub const ELFMAG2: c_char = 'L' as c_char;
pub const EI_MAG3: usize = 3;
pub const ELFMAG3: c_char = 'F' as c_char;
pub const ELFMAG: &'static str = "\x7fELF";
pub const ELFMAG: &str = "\x7fELF";
pub const SELFMAG: usize = 4;
pub const EI_CLASS: usize = 4;
pub const ELFCLASSNONE: usize = 0;
@@ -774,8 +774,8 @@ pub struct Elf64_Nhdr {
pub n_type: Elf64_Word,
}
pub const ELF_NOTE_SOLARIS: &'static str = "SUNW Solaris";
pub const ELF_NOTE_GNU: &'static str = "GNU";
pub const ELF_NOTE_SOLARIS: &str = "SUNW Solaris";
pub const ELF_NOTE_GNU: &str = "GNU";
pub const ELF_NOTE_PAGESIZE_HINT: usize = 1;
+15 -15
View File
@@ -80,7 +80,7 @@ pub unsafe extern "C" fn glob(
}
let base_path = unsafe {
CStr::from_bytes_with_nul_unchecked(if glob_expr.to_bytes().get(0) == Some(&b'/') {
CStr::from_bytes_with_nul_unchecked(if glob_expr.to_bytes().first() == Some(&b'/') {
b"/\0"
} else {
b"\0"
@@ -125,7 +125,7 @@ pub unsafe extern "C" fn glob(
let mut pathv: Box<Vec<*mut c_char>>;
if flags & GLOB_APPEND == GLOB_APPEND {
pathv = unsafe { Box::from_raw((*pglob).__opaque as *mut _) };
pathv = unsafe { Box::from_raw((*pglob).__opaque.cast()) };
pathv.pop(); // Remove NULL from end
} else {
pathv = Box::new(Vec::new());
@@ -144,8 +144,8 @@ pub unsafe extern "C" fn glob(
pathv.push(ptr::null_mut());
unsafe {
(*pglob).gl_pathv = pathv.as_ptr() as *mut *mut c_char;
(*pglob).__opaque = Box::into_raw(pathv) as *mut _;
(*pglob).gl_pathv = pathv.as_ptr().cast_mut();
(*pglob).__opaque = Box::into_raw(pathv).cast();
}
0
@@ -157,7 +157,7 @@ pub unsafe extern "C" fn glob(
pub unsafe extern "C" fn globfree(pglob: *mut glob_t) {
// Retake ownership
if unsafe { !(*pglob).__opaque.is_null() } {
let pathv: Box<Vec<*mut c_char>> = unsafe { Box::from_raw((*pglob).__opaque as *mut _) };
let pathv: Box<Vec<*mut c_char>> = unsafe { Box::from_raw((*pglob).__opaque.cast()) };
for (idx, path) in pathv.into_iter().enumerate() {
if unsafe { idx < (*pglob).gl_offs } {
continue;
@@ -195,7 +195,7 @@ fn list_dir(
let old_errno = platform::ERRNO.get();
let mut results: Vec<DirEntry> = Vec::new();
let open_path = if path.to_bytes().len() == 0 {
let open_path = if path.to_bytes().is_empty() {
unsafe { &CStr::from_bytes_with_nul_unchecked(b".\0") }
} else {
path
@@ -241,13 +241,13 @@ fn list_dir(
let mut link_info = stat::default();
if stat(
full_path.as_ptr() as *const c_char,
&mut link_info as *mut _,
full_path.as_ptr().cast::<c_char>(),
ptr::from_mut(&mut link_info),
) != 0
{
let errno = platform::ERRNO.get();
platform::ERRNO.set(old_errno);
if errfunc(full_path.as_ptr() as *const c_char, errno) != 0 || abort_on_error {
if errfunc(full_path.as_ptr().cast::<c_char>(), errno) != 0 || abort_on_error {
return Err(GLOB_ABORTED);
}
}
@@ -288,7 +288,7 @@ fn inner_glob(
// Remove any '/' chars at the start of the expression
let glob_expr = {
let mut expr = glob_expr.to_bytes_with_nul();
while expr.get(0) == Some(&b'/') {
while expr.first() == Some(&b'/') {
expr = &expr[1..];
}
unsafe { CStr::from_bytes_with_nul_unchecked(expr) }
@@ -353,7 +353,7 @@ fn inner_glob(
for entry in list_dir(current_dir, errfunc, flags & GLOB_ERR == GLOB_ERR)? {
// If we still have pattern to match ignore non-directories
if new_glob_expr.to_bytes().len() != 0 && !entry.is_dir {
if !new_glob_expr.to_bytes().is_empty() && !entry.is_dir {
continue;
}
@@ -373,7 +373,7 @@ fn inner_glob(
if unsafe {
fnmatch(
pattern.as_ptr() as *const c_char,
pattern.as_ptr().cast::<c_char>(),
entry.name.as_ptr(),
fnmatch_flags,
)
@@ -389,15 +389,15 @@ fn inner_glob(
}
// It is an error if we don't find a directory when we expect one
if matches.len() == 0 && new_glob_expr.to_bytes().len() != 0 {
if matches.is_empty() && !new_glob_expr.to_bytes().is_empty() {
let mut path = current_dir.to_bytes().to_vec();
path.extend_from_slice(&pattern);
if unsafe { errfunc(path.as_ptr() as *const c_char, ENOENT) } != 0
if unsafe { errfunc(path.as_ptr().cast::<c_char>(), ENOENT) } != 0
|| flags & GLOB_ERR == GLOB_ERR
{
return Err(GLOB_ABORTED);
}
}
return Ok(matches);
Ok(matches)
}