From 364569366be8a63717264be304cc72a4456f7184 Mon Sep 17 00:00:00 2001 From: sourceturner <126549-sourceturner@users.noreply.gitlab.redox-os.org> Date: Fri, 5 Jun 2026 21:57:23 +0200 Subject: [PATCH] fix os-test for glob() --- src/header/glob/mod.rs | 76 ++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/src/header/glob/mod.rs b/src/header/glob/mod.rs index fcbaa7f7b0..877cce9463 100644 --- a/src/header/glob/mod.rs +++ b/src/header/glob/mod.rs @@ -87,42 +87,6 @@ pub unsafe extern "C" fn glob( }) }; - let errfunc = match errfunc { - Some(f) => f, - None => default_errfunc, - }; - - // Do the globbing - let mut results = match inner_glob(&base_path, &glob_expr, flags, errfunc) { - Ok(res) => res, - Err(e) => return e, - }; - - // Handle GLOB_NOCHECK and no matches - if results.is_empty() { - if flags & GLOB_NOCHECK == GLOB_NOCHECK { - results.push(glob_expr.to_owned_cstring()); - } else { - return GLOB_NOMATCH; - } - } - - // Handle GLOB_NOSORT - if flags & GLOB_NOSORT != GLOB_NOSORT { - results.sort(); - } - - // Set gl_pathc - if flags & GLOB_APPEND == GLOB_APPEND { - unsafe { - (*pglob).gl_pathc += results.len(); - } - } else { - unsafe { - (*pglob).gl_pathc = results.len(); - } - } - let mut pathv: Box>; if flags & GLOB_APPEND == GLOB_APPEND { pathv = unsafe { Box::from_raw((*pglob).__opaque.cast()) }; @@ -138,17 +102,49 @@ pub unsafe extern "C" fn glob( } } - pathv.reserve_exact(results.len() + 1); - pathv.extend(results.into_iter().map(|s| s.into_raw())); + let errfunc = match errfunc { + Some(f) => f, + None => default_errfunc, + }; + // Do the globbing + let return_value = match inner_glob(&base_path, &glob_expr, flags, errfunc) { + Ok(mut results) => { + // Handle GLOB_NOCHECK and no matches + if results.is_empty() && flags & GLOB_NOCHECK != GLOB_NOCHECK { + GLOB_NOMATCH + } else { + if results.is_empty() { + results.push(glob_expr.to_owned_cstring()); + } + + // Handle GLOB_NOSORT + if flags & GLOB_NOSORT != GLOB_NOSORT { + results.sort(); + } + + unsafe { + (*pglob).gl_pathc += results.len(); + } + + pathv.reserve_exact(results.len()); + pathv.extend(results.into_iter().map(|s| s.into_raw())); + + 0 + } + } + Err(e) => e, + }; + + // add terminating NULL + pathv.reserve_exact(1); pathv.push(ptr::null_mut()); - unsafe { (*pglob).gl_pathv = pathv.as_ptr().cast_mut(); (*pglob).__opaque = Box::into_raw(pathv).cast(); } - 0 + return_value } /// See .