2018-02-25 17:05:13 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2018-03-01 06:55:28 +03:00
|
|
|
#include <wait.h>
|
2018-11-05 07:51:29 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
2018-02-25 17:05:13 +03:00
|
|
|
|
|
|
|
int system(const char * command) {
|
|
|
|
char * args[] = {
|
|
|
|
"/bin/sh",
|
|
|
|
"-c",
|
|
|
|
(char *)command,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
pid_t pid = fork();
|
|
|
|
if (!pid) {
|
|
|
|
execvp(args[0], args);
|
|
|
|
exit(1);
|
2022-02-02 06:08:44 +03:00
|
|
|
__builtin_unreachable(); /* With -ffreestanding, gcc doesn't realize exit() doesn't return. */
|
2018-02-25 17:05:13 +03:00
|
|
|
} else {
|
|
|
|
int status;
|
|
|
|
waitpid(pid, &status, 0);
|
2018-11-05 07:51:29 +03:00
|
|
|
return WEXITSTATUS(status);
|
2018-02-25 17:05:13 +03:00
|
|
|
}
|
|
|
|
}
|