diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-11-08 23:42:31 +0100 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-11-09 00:13:56 +0100 |
| commit | 9e4b252a5bbe1f8bf829af85c76cfb1e89c55c7e (patch) | |
| tree | 79746fda99e6adab5539b1aab51be35edcfe024e | |
| parent | b412a627c2936b4cf8651316e5c27f5579441eff (diff) | |
| download | pipeln-9e4b252a5bbe1f8bf829af85c76cfb1e89c55c7e.tar.gz pipeln-9e4b252a5bbe1f8bf829af85c76cfb1e89c55c7e.zip | |
Use execvp() for path resolution
| -rw-r--r-- | pipeln.c | 43 |
1 files changed, 1 insertions, 42 deletions
@@ -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]); } |
