Simply put: One wants to (largely) ignore the error if there's a problem with the directory prefix from the search path; and one wants to retain the error if there's a problem with the final pathname component, the name that is being searched for or the actual node that it names. Unfortunately, execve() can return EACCESS in both cases, and simply deciding to exit the loop based upon nothing but the errno value is therefore an unworkable strategy.
Can you elaborate why you need to differentiate between error in the directory prefix and error in the final pathname component? Why do you think that retaining the error (and failing the pathexec) is better if there is a problem with the final pathname component? IMO, if the binary there is unsuitable for executing, it makes sense to move on to the next path. I'm going to add ENOTDIR support to the skalibs' pathexec_run; I'm interested in knowing why you think it's not good enough. -- Laurent