* Merged with tip.
[cacao.git] / src / native / vm / gnu / gnu_classpath_VMSystemProperties.c
1 /* src/native/vm/gnu/gnu_classpath_VMSystemProperties.c
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "vm/types.h"
32
33 #include "mm/memory.h"
34
35 #include "native/jni.h"
36 #include "native/native.h"
37
38 #include "native/include/java_util_Properties.h"
39
40 #include "native/include/gnu_classpath_VMSystemProperties.h"
41
42 #include "vm/exceptions.h"
43 #include "vm/properties.h"
44 #include "vm/vm.h"
45
46
47 /* native methods implemented by this file ************************************/
48
49 static JNINativeMethod methods[] = {
50         { "preInit",  "(Ljava/util/Properties;)V", (void *) (ptrint) &Java_gnu_classpath_VMSystemProperties_preInit  },
51         { "postInit", "(Ljava/util/Properties;)V", (void *) (ptrint) &Java_gnu_classpath_VMSystemProperties_postInit },
52 };
53
54
55 /* _Jv_gnu_classpat_VMSystemProperties_init ************************************
56
57    Register native functions.
58
59 *******************************************************************************/
60
61 void _Jv_gnu_classpath_VMSystemProperties_init(void)
62 {
63         utf *u;
64
65         u = utf_new_char("gnu/classpath/VMSystemProperties");
66
67         native_method_register(u, methods, NATIVE_METHODS_COUNT);
68 }
69
70
71 /*
72  * Class:     gnu/classpath/VMSystemProperties
73  * Method:    preInit
74  * Signature: (Ljava/util/Properties;)V
75  */
76 JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_preInit(JNIEnv *env, jclass clazz, java_util_Properties *properties)
77 {
78         java_handle_t *p;
79
80         p = (java_handle_t *) properties;
81
82         if (p == NULL) {
83                 exceptions_throw_nullpointerexception();
84                 return;
85         }
86
87         /* fill the java.util.Properties object */
88
89         properties_system_add_all(p);
90 }
91
92
93 /*
94  * Class:     gnu/classpath/VMSystemProperties
95  * Method:    postInit
96  * Signature: (Ljava/util/Properties;)V
97  */
98 JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_postInit(JNIEnv *env, jclass clazz, java_util_Properties *properties)
99 {
100         java_handle_t *p;
101 #if defined(ENABLE_JRE_LAYOUT)
102         char *java_home;
103         char *path;
104         s4    len;
105 #endif
106
107         p = (java_handle_t *) properties;
108
109         if (p == NULL) {
110                 exceptions_throw_nullpointerexception();
111                 return;
112         }
113
114         /* post-set some properties */
115
116 #if defined(ENABLE_JRE_LAYOUT)
117         /* XXX when we do it that way, we can't set these properties on
118            commandline */
119
120         java_home = properties_get("java.home");
121
122         properties_system_add(p, "gnu.classpath.home", java_home);
123
124         len =
125                 strlen("file://") +
126                 strlen(java_home) +
127                 strlen("/lib") +
128                 strlen("0");
129
130         path = MNEW(char, len);
131
132         strcpy(path, "file://");
133         strcat(path, java_home);
134         strcat(path, "/lib");
135
136         properties_system_add(p, "gnu.classpath.home.url", path);
137
138         MFREE(path, char, len);
139 #endif
140 }
141
142
143 /*
144  * These are local overrides for various environment variables in Emacs.
145  * Please do not remove this and leave it at the end of the file, where
146  * Emacs will automagically detect them.
147  * ---------------------------------------------------------------------
148  * Local variables:
149  * mode: c
150  * indent-tabs-mode: t
151  * c-basic-offset: 4
152  * tab-width: 4
153  * End:
154  */