From e5689df37d158594b9f0b4c122c5a08a07562cc6 Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Tue, 20 Aug 2024 14:07:27 +0200 Subject: Fix glob() function Fixed glob() function to return GLOB_NOMATCH if pattern does not match any existing pathname (and GLOB_NOCHECK was not set in flags). --- newlib/libc/include/glob.h | 1 + newlib/libc/posix/glob.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/newlib/libc/include/glob.h b/newlib/libc/include/glob.h index 7a300e6..c14840c 100644 --- a/newlib/libc/include/glob.h +++ b/newlib/libc/include/glob.h @@ -80,6 +80,7 @@ typedef struct { #define GLOB_NOSPACE (-1) /* Malloc call failed. */ #define GLOB_ABEND (-2) /* Unignored error. */ +#define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */ __BEGIN_DECLS int glob(const char *__restrict, int, int (*)(const char *, int), diff --git a/newlib/libc/posix/glob.c b/newlib/libc/posix/glob.c index 5e6c2fc..20eec02 100644 --- a/newlib/libc/posix/glob.c +++ b/newlib/libc/posix/glob.c @@ -502,11 +502,14 @@ glob0(pattern, pglob, limit) * and the pattern did not contain any magic characters * GLOB_NOMAGIC is there just for compatibility with csh. */ - if (pglob->gl_pathc == oldpathc && - ((pglob->gl_flags & GLOB_NOCHECK) || - ((pglob->gl_flags & GLOB_NOMAGIC) && - !(pglob->gl_flags & GLOB_MAGCHAR)))) - return(globextend(pattern, pglob, limit)); + if (pglob->gl_pathc == oldpathc) { + if ((pglob->gl_flags & GLOB_NOCHECK) || + ((pglob->gl_flags & GLOB_NOMAGIC) && + !(pglob->gl_flags & GLOB_MAGCHAR))) + return(globextend(pattern, pglob, limit)); + else + return(GLOB_NOMATCH); + } else if (!(pglob->gl_flags & GLOB_NOSORT)) qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc, pglob->gl_pathc - oldpathc, sizeof(char *), compare); -- cgit v1.1