diff options
author | Jordi Sanfeliu <jordi@fibranet.cat> | 2024-08-20 14:07:27 +0200 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2024-08-20 14:42:03 +0200 |
commit | e5689df37d158594b9f0b4c122c5a08a07562cc6 (patch) | |
tree | b3a0eb31510c4d5b41f7152e89a40855a255dab9 | |
parent | a86f468f96949d8b2d9c2ad11cfb6d99def44f38 (diff) | |
download | newlib-e5689df37d158594b9f0b4c122c5a08a07562cc6.zip newlib-e5689df37d158594b9f0b4c122c5a08a07562cc6.tar.gz newlib-e5689df37d158594b9f0b4c122c5a08a07562cc6.tar.bz2 |
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).
-rw-r--r-- | newlib/libc/include/glob.h | 1 | ||||
-rw-r--r-- | 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); |