diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2020-09-18 17:34:03 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2020-09-18 17:34:03 -0400 |
commit | ccf75c74bdac06eec97a2a6a5228c2e706c121bd (patch) | |
tree | 0e9b682bbdf15f9da668f7fe343a19ed17371b74 /eval.c | |
parent | 0aa71f890777d2aaddeca53384b94742e4b2678b (diff) | |
download | bfs-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 'eval.c')
-rw-r--r-- | eval.c | 8 |
1 files changed, 3 insertions, 5 deletions
@@ -484,12 +484,10 @@ bool eval_lname(const struct expr *expr, struct eval_state *state) { goto done; } - const struct bfs_stat *statbuf = eval_stat(state); - if (!statbuf) { - goto done; - } + const struct bfs_stat *statbuf = bftw_cached_stat(ftwbuf, BFS_STAT_NOFOLLOW); + size_t len = statbuf ? statbuf->size : 0; - name = xreadlinkat(ftwbuf->at_fd, ftwbuf->at_path, statbuf->size); + name = xreadlinkat(ftwbuf->at_fd, ftwbuf->at_path, len); if (!name) { eval_report_error(state); goto done; |