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