path: Improve $PATH search directory case
authorChris Down <chris@chrisdown.name>
Wed, 26 Aug 2020 17:49:27 +0000 (18:49 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 20 Sep 2020 10:37:40 +0000 (12:37 +0200)
commit0783b4f8cecda4f21e9021495377e2c807a32a5e
tree56faf4f86d28752a2f98e3388db9cc6516a61200
parentd0735d81d406d51d320b190e522979200f5b3a8e
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.

(cherry picked from commit 33e1a5d8d3f792e1d98377fe439e123231032ec7)
(cherry picked from commit a4236a27644705e58836f5d547d5aef50d568c11)
(cherry picked from commit 6a30d4e98032575d385a09d15782be74cbef6dfe)
src/basic/path-util.c