summaryrefslogtreecommitdiffstats
path: root/color.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2020-09-18 17:34:03 -0400
committerTavian Barnes <tavianator@tavianator.com>2020-09-18 17:34:03 -0400
commitccf75c74bdac06eec97a2a6a5228c2e706c121bd (patch)
tree0e9b682bbdf15f9da668f7fe343a19ed17371b74 /color.c
parent0aa71f890777d2aaddeca53384b94742e4b2678b (diff)
downloadbfs-ccf75c74bdac06eec97a2a6a5228c2e706c121bd.tar.xz
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.
Diffstat (limited to 'color.c')
-rw-r--r--color.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/color.c b/color.c
index 11684ef..4b70e19 100644
--- a/color.c
+++ b/color.c
@@ -841,11 +841,8 @@ static int print_path(CFILE *cfile, const struct BFTW *ftwbuf) {
static int print_link_target(CFILE *cfile, const struct BFTW *ftwbuf) {
int ret = -1;
- size_t len = 0;
- const struct bfs_stat *statbuf = bftw_stat(ftwbuf, BFS_STAT_NOFOLLOW);
- if (statbuf) {
- len = statbuf->size;
- }
+ 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) {