Simplify AccessCommand

No longer need to do a path search in the indirect case, nor check for
the .ape file's presence.
This commit is contained in:
Jōshin 2024-01-07 08:20:17 -05:00
parent 57435d0283
commit a13ea13b19
No known key found for this signature in database

View file

@ -325,17 +325,7 @@ static char AccessCommand(struct PathSearcher *ps, unsigned long pathlen) {
if (pathlen && ps->path[pathlen - 1] != '/') ps->path[pathlen++] = '/';
memmove(ps->path + pathlen, ps->name, ps->namelen);
ps->path[pathlen + ps->namelen] = 0;
if (!access(ps->path, X_OK)) {
if (ps->indirect) {
ps->namelen -= 4;
ps->path[pathlen + ps->namelen] = 0;
if (access(ps->path, X_OK) < 0) {
Pexit(ps->path, -errno, "access(X_OK)");
}
}
return 1;
}
return 0;
return !access(ps->path, X_OK);
}
static char SearchPath(struct PathSearcher *ps) {
@ -382,6 +372,7 @@ static char *Commandv(struct PathSearcher *ps, const char *name,
const char *syspath) {
ps->syspath = syspath ? syspath : "/bin:/usr/local/bin:/usr/bin";
if (!(ps->namelen = StrLen((ps->name = name)))) return 0;
if (ps->indirect) ps->namelen -= 4;
if (ps->namelen + 1 > sizeof(ps->path)) return 0;
if (FindCommand(ps)) {
return ps->path;