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.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'bftw.h') diff --git a/bftw.h b/bftw.h index 0a4f2aa..2198b52 100644 --- a/bftw.h +++ b/bftw.h @@ -130,6 +130,19 @@ struct BFTW { */ const struct bfs_stat *bftw_stat(const struct BFTW *ftwbuf, enum bfs_stat_flag flags); +/** + * Get bfs_stat() info for a file encountered during bftw(), if it has already + * been cached. + * + * @param ftwbuf + * bftw() data for the file to stat. + * @param flags + * flags for bfs_stat(). Pass ftwbuf->stat_flags for the default flags. + * @return + * A pointer to a bfs_stat() buffer, or NULL if no stat info is cached. + */ +const struct bfs_stat *bftw_cached_stat(const struct BFTW *ftwbuf, enum bfs_stat_flag flags); + /** * Get the type of a file encountered during bftw(), with flags controlling * whether to follow links. This function will avoid calling bfs_stat() if -- cgit v1.2.3