diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2018-09-19 18:11:39 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2018-09-19 18:11:39 -0400 |
commit | a68b6d13ef4137596d4d9ec6f653c76503cc7702 (patch) | |
tree | 4366004338853e4f0adeda863fb35934fca780de | |
parent | abf4394ae34bf25a17efb9fa560791005a6b217b (diff) | |
download | bfs-a68b6d13ef4137596d4d9ec6f653c76503cc7702.tar.xz |
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.
-rw-r--r-- | spawn.c | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -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); } |