Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <sys/wait.h>
- #include <stdio.h>
- enum { BASEEXITCODE = 128 };
- int
- mysys(const char *str)
- {
- int pid = fork(), status;
- if (pid == -1) {
- return -1;
- } else if (!pid) {
- if (execl("/bin/sh", "sh", "-c", str, (char *) 0) == -1) {
- _exit(BASEEXITCODE - 1);
- }
- }
- waitpid(pid, &status, 0);
- if (WIFEXITED(status)) {
- return WEXITSTATUS(status);
- } else {
- return (BASEEXITCODE + WTERMSIG(status));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement