mass rename and rebranding from xwt to ibex - fixed to use ixt files
[org.ibex.core.git] / src / org / ibex / plat / POSIX.cc
diff --git a/src/org/ibex/plat/POSIX.cc b/src/org/ibex/plat/POSIX.cc
new file mode 100644 (file)
index 0000000..869e275
--- /dev/null
@@ -0,0 +1,60 @@
+// Copyright 2002 Adam Megacz, see the COPYING file for licensing [LGPL]
+// see below for copyright information on the second portion of this file
+
+#include "GCJ.cc"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <java/lang/String.h>
+
+// FIXME: we don't need all these
+#include <java/lang/String.h>
+#include <org/ibex/Surface.h>
+#include <org/ibex/Picture.h>
+#include <org/ibex/js/JS.h>
+#include <org/ibex/Box.h>
+#include <org/ibex/util/Semaphore.h>
+#include <org/ibex/Platform.h>
+#include <java/lang/Long.h>
+#include <java/util/Hashtable.h>
+#include <org/ibex/util/Log.h>
+#include <org/ibex/plat/POSIX.h>
+#include <java/lang/System.h>
+#include <java/io/PrintStream.h>
+
+jstring org::ibex::plat::POSIX::_getEnv(jstring key) {
+    int len = JvGetStringUTFLength(key);
+    char buf[len + 1];
+    JvGetStringUTFRegion(key, 0, len, buf);
+    buf[len] = '\0';
+    char* envstr = getenv(buf);
+    return envstr == NULL ? NULL : JvNewStringLatin1(envstr);
+}
+
+void org::ibex::plat::POSIX::spawnChildProcess(JArray<jstring>* cmd) {
+    jstring* cmdstrings = elements(cmd);
+    char* cmd2[cmd->length + 1];
+    cmd2[cmd->length] = NULL;
+    for(int i=0; i<cmd->length; i++) {
+        cmd2[i] = (char*)malloc(JvGetStringUTFLength(cmdstrings[i]));
+        JvGetStringUTFRegion(cmdstrings[i], 0, JvGetStringUTFLength(cmdstrings[i]), cmd2[i]);
+    }
+
+    if (!fork()) {
+        signal(SIGHUP, SIG_IGN);
+        signal(SIGQUIT, SIG_IGN);
+        signal(SIGINT, SIG_IGN);
+        signal(SIGTERM, SIG_IGN);
+
+        // ignore SIGPIPE in case we were launched from a browser and the browser closed
+        signal(SIGPIPE, SIG_IGN);
+
+        execvp(cmd2[0], cmd2);
+    }
+}
+