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. --- printf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'printf.c') diff --git a/printf.c b/printf.c index b9149f3..6eb59dd 100644 --- a/printf.c +++ b/printf.c @@ -310,7 +310,10 @@ static int bfs_printf_l(FILE *file, const struct bfs_printf *directive, const st return 0; } - char *target = xreadlinkat(ftwbuf->at_fd, ftwbuf->at_path, 0); + const struct bfs_stat *statbuf = bftw_cached_stat(ftwbuf, BFS_STAT_NOFOLLOW); + size_t len = statbuf ? statbuf->size : 0; + + char *target = xreadlinkat(ftwbuf->at_fd, ftwbuf->at_path, len); if (!target) { return -1; } -- cgit v1.2.3