From c601174268e0ea6cad93a733cecb3a07b2c503a6 Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sun, 5 Feb 2012 11:20:09 -0800 Subject: [PATCH] sh: Use dirent.d_type in pathname generation. This improves performance for globs where a slash or another component follows a component with metacharacters by eliminating unnecessary attempts to open directories that are not. Obtained-from: FreeBSD 228942 --- bin/sh/expand.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/sh/expand.c b/bin/sh/expand.c index 2cb334030b..c10a0f5ceb 100644 --- a/bin/sh/expand.c +++ b/bin/sh/expand.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)expand.c 8.5 (Berkeley) 5/15/95 - * $FreeBSD: src/bin/sh/expand.c,v 1.92 2011/12/28 23:30:17 jilles Exp $ + * $FreeBSD: src/bin/sh/expand.c,v 1.93 2011/12/28 23:40:46 jilles Exp $ */ #include @@ -1291,6 +1291,10 @@ expmeta(char *enddir, char *name) if (atend) addfname(expdir); else { + if (dp->d_type != DT_UNKNOWN && + dp->d_type != DT_DIR && + dp->d_type != DT_LNK) + continue; if (enddir + namlen + 2 > expdir_end) continue; enddir[namlen] = '/'; -- 2.41.0