From b95de98a6b0984d644087bbb82d9c228381e27db Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Sat, 11 Jan 2014 21:12:27 +0000 Subject: find: Allow -type d without statting everything. fts(3) detects directories even in FTS_NOSTAT mode (so it can descend into them). No functional change is intended, but find commands that use -type d but no primaries that still require stat/lstat calls make considerably fewer system calls. --- usr.bin/find/function.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index 9f156756cc561..a71369b5db7f2 100644 --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -1552,7 +1552,12 @@ c_sparse(OPTION *option, char ***argvp __unused) int f_type(PLAN *plan, FTSENT *entry) { - return (entry->fts_statp->st_mode & S_IFMT) == plan->m_data; + if (plan->m_data == S_IFDIR) + return (entry->fts_info == FTS_D || entry->fts_info == FTS_DC || + entry->fts_info == FTS_DNR || entry->fts_info == FTS_DOT || + entry->fts_info == FTS_DP); + else + return (entry->fts_statp->st_mode & S_IFMT) == plan->m_data; } PLAN * @@ -1563,7 +1568,8 @@ c_type(OPTION *option, char ***argvp) mode_t mask; typestring = nextarg(option, argvp); - ftsoptions &= ~FTS_NOSTAT; + if (typestring[0] != 'd') + ftsoptions &= ~FTS_NOSTAT; switch (typestring[0]) { case 'b': -- cgit v1.3