path: Improve $PATH search directory case
authorChris Down <chris@chrisdown.name>
Wed, 26 Aug 2020 17:49:27 +0000 (18:49 +0100)
committerChris Down <chris@chrisdown.name>
Wed, 26 Aug 2020 23:52:20 +0000 (00:52 +0100)
commit33e1a5d8d3f792e1d98377fe439e123231032ec7
treebb8544e1f88500a816c7337e8ef266600245261e
parentbb2aee7d114841d1c095121f0ac6b3e9bc0342dc
path: Improve $PATH search directory case

Previously:

1. last_error wouldn't be updated with errors from is_dir;
2. We'd always issue a stat(), even for binaries without execute;
3. We used stat() instead of access(), which is cheaper.

This change avoids all of those, by only checking inside X_OK-positive
case whether access() works on the path with an extra slash appended.
Thanks to Lennart for the suggestion.
src/basic/path-util.c