1 #include "lib.h" 2 #include <stdlib.h> 3 #include <sys/wait.h> 4 #include <unistd.h> 5 6 int 7 system(const char *s) 8 { 9 int w, status; 10 pid_t pid; 11 12 if(!s) 13 return 1; /* a command interpreter is available */ 14 pid = fork(); 15 if(pid == 0) { 16 execl("/bin/rc", "rc", "-c", s, 0); 17 _exit(1); 18 } 19 if(pid < 0){ 20 _syserrno(); 21 return -1; 22 } 23 for(;;) { 24 w = wait(&status); 25 if(w == -1 || w == pid) 26 break; 27 } 28 29 if(w == -1){ 30 _syserrno(); 31 return w; 32 } 33 return status; 34 } 35