|
@@ -1,27 +1,28 @@
|
|
|
#include <stdio.h>
|
|
|
|
|
|
-/*
|
|
|
+#ifndef __WIN32
|
|
|
+#include <stddef.h>
|
|
|
#include <sys/wait.h>
|
|
|
#include <errno.h>
|
|
|
+#include <sys/types.h>
|
|
|
+#endif
|
|
|
|
|
|
-int bmx_waitpid(pid_t pid) {
|
|
|
-
|
|
|
+int bmx_system(const char * c) {
|
|
|
+#ifdef __WIN32
|
|
|
+ return system(c);
|
|
|
+#else
|
|
|
int status;
|
|
|
- pid_t p = waitpid(pid, &status, WUNTRACED);
|
|
|
-
|
|
|
- if (p > 0) {
|
|
|
- if (WIFEXITED(status)) {
|
|
|
- return WEXITSTATUS(status);
|
|
|
- }
|
|
|
- if (WIFSIGNALED(status)) {
|
|
|
- return WTERMSIG(status);
|
|
|
- }
|
|
|
+ pid_t pid = fork();
|
|
|
+ if (pid == 0) {
|
|
|
+ execl("/bin/sh", "/bin/sh", "-c", c, NULL);
|
|
|
+ _exit(-1);
|
|
|
+ } else if (pid < 0) {
|
|
|
+ status = -1;
|
|
|
} else {
|
|
|
- return errno * -1;
|
|
|
+ if (waitpid(pid, &status, 0) != pid) {
|
|
|
+ status = -1;
|
|
|
+ }
|
|
|
}
|
|
|
- return -999;
|
|
|
-}
|
|
|
-*/
|
|
|
-int bmx_system(const char * c) {
|
|
|
- return system(c);
|
|
|
+ return status;
|
|
|
+#endif
|
|
|
}
|