Mercurial > dnft
diff spawn.cpp @ 0:4171b2d4684b default tip
initial commit
| author | Yasuri <linuxoverwindows@charliesmp.net> |
|---|---|
| date | Sat, 05 Sep 2026 15:35:48 -0500 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spawn.cpp Sat Sep 05 15:35:48 2026 -0500 @@ -0,0 +1,23 @@ +#include <iostream> +#include <unistd.h> +#include <sys/wait.h> +#include <spawn.h> +extern char** environ; // idk what this does +int spawn(char* const argv[], const char* path) +{ + pid_t pid; + int status; + status = posix_spawn(&pid, path, NULL, NULL, const_cast<char* const*>(argv), environ); + if (status != 0) { + std::cerr << "posix_spawn failed:" << strerror(status) << std::endl; + return 1; + } + if (waitpid(pid, &status, 0) == -1) { + perror("waitpid"); + return 1; + } + if (WIFEXITED(status)) { + return WEXITSTATUS(status); + } + return 1; +}
