diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2018-03-28 14:23:57 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2018-04-06 14:44:09 +0200 |
commit | b7df35d081673097a5e4f2cc5fcdfeaceaba16a9 (patch) | |
tree | 028aa047d2376171b848b16bd394e432f6e8b8ef /lib/glob.c | |
parent | 7156e859b6ddf2415a3c572c686df180c90ab249 (diff) | |
download | barebox-b7df35d081673097a5e4f2cc5fcdfeaceaba16a9.tar.gz |
glob: do not unnecessarily opendir() a directory
opendir() can trigger automounts, so do not use it when the
pattern we examine doesn't have any wildcards.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib/glob.c')
-rw-r--r-- | lib/glob.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/glob.c b/lib/glob.c index 5a997ca092..32f7afdce8 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -313,7 +313,7 @@ static int prefix_array(const char *dirname, char **array, size_t n, 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 @@ static int glob_in_dir(const char *pattern, const char *directory, 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 @@ static int glob_in_dir(const char *pattern, const char *directory, return GLOB_ABORTED; } - meta = glob_pattern_p(pattern, !(flags & GLOB_NOESCAPE)); - - if (meta) - flags |= GLOB_MAGCHAR; - while (1) { const char *name; size_t len; |