diff options
author | jilles <jilles@FreeBSD.org> | 2014-01-11 21:12:27 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2014-01-11 21:12:27 +0000 |
commit | 5886553bdc6ea5895266165f9ad3b6ee57de33f1 (patch) | |
tree | 15e7c58199a6769cc5e56c5118a794d8607eb791 /usr.bin | |
parent | 761960c8d5f88bb170cf7010967b94fcae0b2e92 (diff) | |
download | FreeBSD-src-5886553bdc6ea5895266165f9ad3b6ee57de33f1.zip FreeBSD-src-5886553bdc6ea5895266165f9ad3b6ee57de33f1.tar.gz |
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.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/find/function.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index 9f15675..a71369b 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': |