From 0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 12 Feb 2011 00:22:29 -0500 Subject: initial check-in, version 0.5.0 --- src/process/execvp.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/process/execvp.c (limited to 'src/process/execvp.c') diff --git a/src/process/execvp.c b/src/process/execvp.c new file mode 100644 index 00000000..d799ddae --- /dev/null +++ b/src/process/execvp.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +extern char **__environ; + +int execvp(const char *file, char *const argv[]) +{ + const char *p, *z, *path = getenv("PATH"); + int l; + + if (strchr(file, '/')) + return execve(file, argv, __environ); + + /* FIXME: integer overflows */ + if (!path) path = "/usr/local/bin:/bin:/usr/bin"; + l = strlen(file) + strlen(path) + 2; + + for(p=path; p && *p; p=z) { + char b[l]; + z = strchr(p, ':'); + if (z) { + memcpy(b, p, z-p); + b[z++-p] = 0; + } else strcpy(b, p); + strcat(b, "/"); + strcat(b, file); + if (!access(b, X_OK)) + return execve(b, argv, __environ); + } + errno = ENOENT; + return -1; +} -- cgit v1.2.1