summaryrefslogtreecommitdiff
path: root/libc/unistd/execvep.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-10-11 22:51:00 +0000
committerEric Andersen <andersen@codepoet.org>2000-10-11 22:51:00 +0000
commit174dc1b8cd932fb5cd3d50fe5317e0c29ee26c59 (patch)
tree7683117cfc44f8f09610b5f1f48bcdb1524031bb /libc/unistd/execvep.c
parent1eb3e9989a8241c1654788fc7589e1f679e73dff (diff)
Reorg unistd dir
Diffstat (limited to 'libc/unistd/execvep.c')
-rw-r--r--libc/unistd/execvep.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/libc/unistd/execvep.c b/libc/unistd/execvep.c
new file mode 100644
index 000000000..4ac7692e9
--- /dev/null
+++ b/libc/unistd/execvep.c
@@ -0,0 +1,43 @@
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+int execvep(const char *path, char *__const argv[], char *__const envp[])
+{
+ if (!strchr(path, '/')) {
+ char partial[128];
+ char *p = getenv("PATH");
+ char *p2;
+
+ if (!p)
+ p = "/bin:/usr/bin";
+
+ for (; p && *p;) {
+
+ strcpy(partial, p);
+
+ p2 = strchr(partial, ':');
+ if (p2)
+ *p2 = '\0';
+
+ if (strlen(partial))
+ strcat(partial, "/");
+ strcat(partial, path);
+
+ execve(partial, argv, envp);
+
+ if (errno != ENOENT)
+ return -1;
+
+ p2 = strchr(p, ':');
+ if (p2)
+ p = p2 + 1;
+ else
+ p = 0;
+ }
+ return -1;
+ } else
+ return execve(path, argv, envp);
+}