From ccf75c74bdac06eec97a2a6a5228c2e706c121bd Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 18 Sep 2020 17:34:03 -0400 Subject: Don't call stat() just to determine symbolic lengths The new bftw_cached_stat() helper gets us stat info if we already have it, but doesn't call stat() if we don't. In that case we just take a guess for the initial length to readlinkat(). This lets us avoid stat() entirely in many cases for -lname and -printf %l. --- bftw.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'bftw.c') diff --git a/bftw.c b/bftw.c index ff4797d..1296360 100644 --- a/bftw.c +++ b/bftw.c @@ -886,6 +886,14 @@ const struct bfs_stat *bftw_stat(const struct BFTW *ftwbuf, enum bfs_stat_flag f return ret; } +const struct bfs_stat *bftw_cached_stat(const struct BFTW *ftwbuf, enum bfs_stat_flag flags) { + if (flags & BFS_STAT_NOFOLLOW) { + return ftwbuf->lstat_cache.buf; + } else { + return ftwbuf->stat_cache.buf; + } +} + enum bftw_type bftw_type(const struct BFTW *ftwbuf, enum bfs_stat_flag flags) { if (ftwbuf->stat_flags & BFS_STAT_NOFOLLOW) { if ((flags & BFS_STAT_NOFOLLOW) || ftwbuf->type != BFTW_LNK) { -- cgit v1.2.3