diff --git a/lib/glob.c b/lib/glob.c index 5a997ca..32f7afd 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -313,7 +313,7 @@ static int glob_in_dir(const char *pattern, const char *directory, int flags, int (*errfunc) __P((const char *, int)), glob_t *pglob) { - __ptr_t stream; + __ptr_t stream = NULL; struct globlink { struct globlink *next; @@ -323,7 +323,13 @@ size_t nfound = 0; int meta; - stream = opendir(directory); + meta = glob_pattern_p(pattern, !(flags & GLOB_NOESCAPE)); + + if (meta) + flags |= GLOB_MAGCHAR; + + if (meta) + stream = opendir(directory); if (stream == NULL) { if ((errfunc != NULL && (*errfunc) (directory, errno)) || @@ -331,11 +337,6 @@ return GLOB_ABORTED; } - meta = glob_pattern_p(pattern, !(flags & GLOB_NOESCAPE)); - - if (meta) - flags |= GLOB_MAGCHAR; - while (1) { const char *name; size_t len;