summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/ap/plan9/system.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/ape/lib/ap/plan9/system.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/ape/lib/ap/plan9/system.c')
-rwxr-xr-xsys/src/ape/lib/ap/plan9/system.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/sys/src/ape/lib/ap/plan9/system.c b/sys/src/ape/lib/ap/plan9/system.c
new file mode 100755
index 000000000..497b0e1f1
--- /dev/null
+++ b/sys/src/ape/lib/ap/plan9/system.c
@@ -0,0 +1,40 @@
+#include "lib.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+int
+system(const char *s)
+{
+ int w, status;
+ pid_t pid;
+ char cmd[30], *oty;
+
+ oty = getenv("cputype");
+ if(!oty)
+ return -1;
+ if(!s)
+ return 1; /* a command interpreter is available */
+ pid = fork();
+ snprintf(cmd, sizeof cmd, "/%s/bin/ape/sh", oty);
+ if(pid == 0) {
+ execl(cmd, "sh", "-c", s, NULL);
+ _exit(1);
+ }
+ if(pid < 0){
+ _syserrno();
+ return -1;
+ }
+ for(;;) {
+ w = wait(&status);
+ if(w == -1 || w == pid)
+ break;
+ }
+
+ if(w == -1){
+ _syserrno();
+ return w;
+ }
+ return status;
+}