From a13ea13b198b4c8854d21e59efcb71550acbf443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Sun, 7 Jan 2024 08:20:17 -0500 Subject: [PATCH] Simplify AccessCommand No longer need to do a path search in the indirect case, nor check for the .ape file's presence. --- ape/ape-m1.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/ape/ape-m1.c b/ape/ape-m1.c index 1252a11cd..8079bf785 100644 --- a/ape/ape-m1.c +++ b/ape/ape-m1.c @@ -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;