Re: [PATCH] Fix glob() function
Jordi Sanfeliu <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
Hi Corinna, Find the new patch attached. Thanks. -- Jordi Sanfeliu FIBRANET Network Services Provider https://www.fibranet.cat On Tue, 20 Aug 2024, Corinna Vinschen wrote: > Hi Jordi, > > the patch looks good, thank you. Can you please send it as a git patch > created with `git format-patch' and a nice commit message? > > > Thanks, > Corinna >
0001-fixed-glob-function-to-return-GLOB_NOMATCH-if-patter.patch
(text/plain, 1.8 KB)
From: Jordi Sanfeliu <[email protected]> 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 7a300e69d..c14840cf0 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 5e6c2fcba..20eec0263 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); -- 2.46.0