From a68b6d13ef4137596d4d9ec6f653c76503cc7702 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 19 Sep 2018 18:11:39 -0400 Subject: spawn: Implement execvpe() on platforms that lack it Credit to https://github.com/nim-lang/Nim/issues/3138 for the idea to just overwrite environ and call execvp() instead of duplicating the path searching logic. --- spawn.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spawn.c b/spawn.c index 82bce11..a54303f 100644 --- a/spawn.c +++ b/spawn.c @@ -91,6 +91,16 @@ int bfs_spawn_addfchdir(struct bfs_spawn *ctx, int fd) { } } +static int bfs_execvpe(const char *file, char **argv, char **envp) { +#if __GLIBC__ || __linux__ || __NetBSD__ || __OpenBSD__ + return execvpe(file, argv, envp); +#else + extern char **environ; + environ = envp; + return execvp(file, argv); +#endif +} + static void bfs_spawn_exec(const char *file, const struct bfs_spawn *ctx, char **argv, char **envp, int pipefd[2]) { int error; enum bfs_spawn_flags flags = ctx ? ctx->flags : 0; @@ -109,7 +119,7 @@ static void bfs_spawn_exec(const char *file, const struct bfs_spawn *ctx, char * } if (flags & BFS_SPAWN_USEPATH) { - execvpe(file, argv, envp); + bfs_execvpe(file, argv, envp); } else { execve(file, argv, envp); } -- cgit v1.2.3