bugfix in url parsing for HTTP.java
[org.ibex.core.git] / src / org / ibex / plat / POSIX.cc
1 // Copyright 2002 Adam Megacz, see the COPYING file for licensing [LGPL]
2 // see below for copyright information on the second portion of this file
3
4 #include <java/lang/String.h>
5 #include <org/ibex/graphics/Surface.h>
6 #include <org/ibex/graphics/Picture.h>
7 #include <org/ibex/js/JS.h>
8 #include <org/ibex/core/Box.h>
9 #include <org/ibex/util/Semaphore.h>
10 #include <org/ibex/plat/Platform.h>
11 #include <java/lang/Long.h>
12 #include <java/util/Hashtable.h>
13 #include <org/ibex/util/Log.h>
14 #include <org/ibex/plat/POSIX.h>
15 #include <java/lang/System.h>
16 #include <java/io/PrintStream.h>
17
18 #include "GCJ.cc"
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <sys/ipc.h>
24 #include <sys/shm.h>
25 #include <sys/types.h>
26 #include <signal.h>
27
28 jstring org::ibex::plat::POSIX::_getEnv(jstring key) {
29     int len = JvGetStringUTFLength(key);
30     char buf[len + 1];
31     JvGetStringUTFRegion(key, 0, len, buf);
32     buf[len] = '\0';
33     char* envstr = getenv(buf);
34     return envstr == NULL ? NULL : JvNewStringLatin1(envstr);
35 }
36
37 void org::ibex::plat::POSIX::spawnChildProcess(JArray<jstring>* cmd) {
38     jstring* cmdstrings = elements(cmd);
39     char* cmd2[cmd->length + 1];
40     cmd2[cmd->length] = NULL;
41     for(int i=0; i<cmd->length; i++) {
42         cmd2[i] = (char*)malloc(JvGetStringUTFLength(cmdstrings[i]));
43         JvGetStringUTFRegion(cmdstrings[i], 0, JvGetStringUTFLength(cmdstrings[i]), cmd2[i]);
44     }
45
46     if (!fork()) {
47         signal(SIGHUP, SIG_IGN);
48         signal(SIGQUIT, SIG_IGN);
49         signal(SIGINT, SIG_IGN);
50         signal(SIGTERM, SIG_IGN);
51
52         // ignore SIGPIPE in case we were launched from a browser and the browser closed
53         signal(SIGPIPE, SIG_IGN);
54
55         execvp(cmd2[0], cmd2);
56     }
57 }
58