Advertisement
wowonline

Untitled

Nov 20th, 2021
1,267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <sys/wait.h>
  3. #include <stdio.h>
  4.  
  5. enum { BASEEXITCODE = 128 };
  6.  
  7. int
  8. mysys(const char *str)
  9. {
  10.     int pid = fork(), status;
  11.     if (pid == -1) {
  12.         return -1;
  13.     } else if (!pid) {
  14.         if (execl("/bin/sh", "sh", "-c", str, (char *) 0) == -1) {
  15.             _exit(BASEEXITCODE - 1);
  16.         }
  17.     }
  18.  
  19.  
  20.     waitpid(pid, &status, 0);
  21.     if (WIFEXITED(status)) {
  22.         return WEXITSTATUS(status);
  23.     } else {
  24.         return (BASEEXITCODE + WTERMSIG(status));
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement