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