pipeln

Pipeline creation tool
git clone https://git.sinitax.com/sinitax/pipeln
Log | Files | Refs | README | LICENSE | sfeed.txt

commit 9e4b252a5bbe1f8bf829af85c76cfb1e89c55c7e
parent b412a627c2936b4cf8651316e5c27f5579441eff
Author: Louis Burda <quent.burda@gmail.com>
Date:   Wed,  8 Nov 2023 23:42:31 +0100

Use execvp() for path resolution

Diffstat:
Mpipeln.c | 43+------------------------------------------
1 file changed, 1 insertion(+), 42 deletions(-)

diff --git a/pipeln.c b/pipeln.c @@ -31,44 +31,6 @@ die(const char *fmt, ...) exit(1); } -static char * -findbin(const char *name) -{ - static char pathbuf[PATH_MAX]; - const char *tok, *sep, *end; - struct dirent *ent; - size_t entlen; - DIR *dir; - - tok = getenv("PATH"); - while (tok) { - sep = strchr(tok, ':'); - end = sep ? sep : tok + strlen(tok); - entlen = (size_t) (end - tok); - if (entlen > 0 && entlen < PATH_MAX) { - strncpy(pathbuf, tok, entlen); - pathbuf[entlen] = '\0'; - dir = opendir(pathbuf); - if (dir) { - while ((ent = readdir(dir))) { - if (entlen + 1 + strlen(name) >= PATH_MAX) - continue; - if (!strcmp(ent->d_name, name)) { - strcat(pathbuf, "/"); - strcat(pathbuf, name); - closedir(dir); - return pathbuf; - } - } - closedir(dir); - } - } - tok = sep ? sep + 1 : NULL; - } - - die("findbin %s", name); -} - static pid_t run(int *in, int *out, const char **argv) { @@ -76,9 +38,6 @@ run(int *in, int *out, const char **argv) if (!argv[0]) die("run: empty command"); - if (strncmp(argv[0], "/", 1) && strncmp(argv[0], "./", 2)) - argv[0] = findbin(argv[0]); - child = fork(); if (child < 0) die("fork:"); @@ -95,7 +54,7 @@ run(int *in, int *out, const char **argv) close(out[0]); close(out[1]); } - execv(argv[0], (char *const *) argv); + execvp(argv[0], (char *const *) argv); die("execv %s:", argv[0]); }