Merged revisions 7797-7917 via svnmerge from
[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    $Id: gnu_classpath_VMSystemProperties.c 7910 2007-05-16 08:02:52Z twisti $
26
27 */
28
29
30 #include "config.h"
31
32 #include <stdlib.h>
33 #include <string.h>
34
35 #include "vm/types.h"
36
37 #include "mm/memory.h"
38
39 #include "native/jni.h"
40 #include "native/native.h"
41
42 #include "native/include/java_util_Properties.h"
43
44 #include "native/include/gnu_classpath_VMSystemProperties.h"
45
46 #include "vm/exceptions.h"
47 #include "vm/properties.h"
48 #include "vm/vm.h"
49
50
51 /* native methods implemented by this file ************************************/
52
53 static JNINativeMethod methods[] = {
54         { "preInit",  "(Ljava/util/Properties;)V", (void *) (ptrint) &Java_gnu_classpath_VMSystemProperties_preInit  },
55         { "postInit", "(Ljava/util/Properties;)V", (void *) (ptrint) &Java_gnu_classpath_VMSystemProperties_postInit },
56 };
57
58
59 /* _Jv_gnu_classpat_VMSystemProperties_init ************************************
60
61    Register native functions.
62
63 *******************************************************************************/
64
65 void _Jv_gnu_classpath_VMSystemProperties_init(void)
66 {
67         utf *u;
68
69         u = utf_new_char("gnu/classpath/VMSystemProperties");
70
71         native_method_register(u, methods, NATIVE_METHODS_COUNT);
72 }
73
74
75 /*
76  * Class:     gnu/classpath/VMSystemProperties
77  * Method:    preInit
78  * Signature: (Ljava/util/Properties;)V
79  */
80 JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_preInit(JNIEnv *env, jclass clazz, java_util_Properties *properties)
81 {
82         java_objectheader *p;
83
84         p = (java_objectheader *) properties;
85
86         if (p == NULL) {
87                 exceptions_throw_nullpointerexception();
88                 return;
89         }
90
91         /* fill the java.util.Properties object */
92
93         properties_system_add_all(p);
94 }
95
96
97 /*
98  * Class:     gnu/classpath/VMSystemProperties
99  * Method:    postInit
100  * Signature: (Ljava/util/Properties;)V
101  */
102 JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_postInit(JNIEnv *env, jclass clazz, java_util_Properties *properties)
103 {
104         java_objectheader *p;
105 #if defined(WITH_JRE_LAYOUT)
106         char *path;
107         s4    len;
108 #endif
109
110         p = (java_objectheader *) properties;
111
112         if (p == NULL) {
113                 exceptions_throw_nullpointerexception();
114                 return;
115         }
116
117         /* post-set some properties */
118
119 #if defined(WITH_JRE_LAYOUT)
120         /* XXX when we do it that way, we can't set these properties on
121            commandline */
122
123         properties_system_add(p, "gnu.classpath.home", cacao_prefix);
124
125         len =
126                 strlen("file://") +
127                 strlen(cacao_prefix) +
128                 strlen("/lib") +
129                 strlen("0");
130
131         path = MNEW(char, len);
132
133         strcpy(path, "file://");
134         strcat(path, cacao_prefix);
135         strcat(path, "/lib");
136
137         properties_system_add(p, "gnu.classpath.home.url", path);
138
139         MFREE(path, char, len);
140 #endif
141 }
142
143
144 /*
145  * These are local overrides for various environment variables in Emacs.
146  * Please do not remove this and leave it at the end of the file, where
147  * Emacs will automagically detect them.
148  * ---------------------------------------------------------------------
149  * Local variables:
150  * mode: c
151  * indent-tabs-mode: t
152  * c-basic-offset: 4
153  * tab-width: 4
154  * End:
155  */