OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [gnu/] [classpath/] [natSystemProperties.cc] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
// natSystemProperties.cc - Implementation of native side of
2
// SystemProperties class.
3
 
4
/* Copyright (C) 2005  Free Software Foundation
5
 
6
   This file is part of libgcj.
7
 
8
This software is copyrighted work licensed under the terms of the
9
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
10
details.  */
11
 
12
#include <config.h>
13
#include <platform.h>
14
 
15
#include <stdlib.h>
16
#include <errno.h>
17
 
18
#ifdef HAVE_PWD_H
19
#include <pwd.h>
20
#endif
21
 
22
#ifdef HAVE_UNAME
23
#include <sys/utsname.h>
24
#endif
25
 
26
#ifdef HAVE_LOCALE_H
27
#include <locale.h>
28
#endif
29
 
30
#ifdef HAVE_LANGINFO_H
31
#include <langinfo.h>
32
#endif
33
 
34
#include <gcj/cni.h>
35
#include <jvm.h>
36
#include <java-props.h>
37
#include <gnu/classpath/SystemProperties.h>
38
#include <java/lang/String.h>
39
#include <jni.h>
40
 
41
char *_Jv_Module_Load_Path = NULL;
42
 
43
#ifdef USE_LTDL
44
#include <ltdl.h>
45
 
46
void
47
_Jv_SetDLLSearchPath (const char *path)
48
{
49
  _Jv_Module_Load_Path = strdup (path);
50
}
51
 
52
#else
53
 
54
void
55
_Jv_SetDLLSearchPath (const char *)
56
{
57
  // Nothing.
58
}
59
 
60
#endif /* USE_LTDL */
61
 
62
#if ! defined (DEFAULT_FILE_ENCODING) && defined (HAVE_ICONV) \
63
    && defined (HAVE_NL_LANGINFO)
64
 
65
static char *
66
file_encoding ()
67
{
68
  setlocale (LC_CTYPE, "");
69
  char *e = nl_langinfo (CODESET);
70
  if (e == NULL || *e == '\0')
71
    e = "8859_1";
72
  return e;
73
}
74
 
75
#define DEFAULT_FILE_ENCODING file_encoding ()
76
 
77
#endif
78
 
79
#ifndef DEFAULT_FILE_ENCODING
80
#define DEFAULT_FILE_ENCODING "8859_1"
81
#endif
82
 
83
static char *default_file_encoding = DEFAULT_FILE_ENCODING;
84
 
85
#if HAVE_GETPWUID_R
86
/* Use overload resolution to find out the signature of getpwuid_r.  */
87
 
88
  /* This is Posix getpwuid_r.  */
89
template <typename T_uid, typename T_passwd, typename T_buf, typename T_len>
90
static inline int
91
getpwuid_adaptor(int (*getpwuid_r)(T_uid user_id, T_passwd *pwd_r,
92
                                   T_buf *buf_r, T_len len_r,
93
                                   T_passwd **pwd_entry_ptr),
94
                 uid_t user_id, struct passwd *pwd_r,
95
                 char *buf_r, size_t len_r, struct passwd **pwd_entry)
96
{
97
  return getpwuid_r (user_id, pwd_r, buf_r, len_r, pwd_entry);
98
}
99
 
100
/* This is used on HPUX 10.20 */
101
template <typename T_uid, typename T_passwd, typename T_buf, typename T_len>
102
static inline int
103
getpwuid_adaptor(int (*getpwuid_r)(T_uid user_id, T_passwd *pwd_r,
104
                                   T_buf *buf_r, T_len len_r),
105
                 uid_t user_id, struct passwd *pwd_r,
106
                 char *buf_r, size_t len_r, struct passwd **pwd_entry)
107
{
108
  return getpwuid_r (user_id, pwd_r, buf_r, len_r);
109
}
110
 
111
/* This is used on IRIX 5.2.  */
112
template <typename T_uid, typename T_passwd, typename T_buf, typename T_len>
113
static inline int
114
getpwuid_adaptor(T_passwd * (*getpwuid_r)(T_uid user_id, T_passwd *pwd_r,
115
                                          T_buf *buf_r, T_len len_r),
116
                 uid_t user_id, struct passwd *pwd_r,
117
                 char *buf_r, size_t len_r, struct passwd **pwd_entry)
118
{
119
  *pwd_entry = getpwuid_r (user_id, pwd_r, buf_r, len_r);
120
  return (*pwd_entry == NULL) ? errno : 0;
121
}
122
#endif
123
 
124
void
125
gnu::classpath::SystemProperties::insertSystemProperties (java::util::Properties *newprops)
126
{
127
  // A convenience define.
128
#define SET(Prop,Val) \
129
        newprops->put(JvNewStringLatin1 (Prop), JvNewStringLatin1 (Val))
130
 
131
  // A mixture of the Java Product Versioning Specification
132
  // (introduced in 1.2), and earlier versioning properties.  Some
133
  // programs rely on seeing values that they expect, so we claim to
134
  // be a 1.4-ish VM for their sake.
135
  SET ("java.version", JV_VERSION);
136
  SET ("java.runtime.version", JV_VERSION);
137
  SET ("java.vendor", "Free Software Foundation, Inc.");
138
  SET ("java.vendor.url", "http://gcc.gnu.org/java/");
139
  SET ("java.class.version", "46.0");
140
  SET ("java.vm.specification.version", "1.0");
141
  SET ("java.vm.specification.name", "Java(tm) Virtual Machine Specification");
142
  SET ("java.vm.specification.vendor", "Sun Microsystems Inc.");
143
  SET ("java.vm.version", __VERSION__);
144
  SET ("java.vm.vendor", "Free Software Foundation, Inc.");
145
  SET ("java.vm.name", "GNU libgcj");
146
  SET ("java.specification.version", JV_API_VERSION);
147
  SET ("java.specification.name", "Java(tm) Platform API Specification");
148
  SET ("java.specification.vendor", "Sun Microsystems Inc.");
149
 
150
  char value[100];
151
#define NAME "GNU libgcj "
152
  strcpy (value, NAME);
153
  strncpy (value + sizeof (NAME) - 1, __VERSION__,
154
           sizeof(value) - sizeof(NAME));
155
  value[sizeof (value) - 1] = '\0';
156
  jstring version = JvNewStringLatin1 (value);
157
  newprops->put (JvNewStringLatin1 ("java.fullversion"), version);
158
  newprops->put (JvNewStringLatin1 ("java.vm.info"), version);
159
 
160
  // This definition is rather arbitrary: we choose $(prefix).  In
161
  // part we do this because most people specify only --prefix and
162
  // nothing else when installing gcj.  Plus, people are free to
163
  // redefine `java.home' with `-D' if necessary.
164
  SET ("java.home", JAVA_HOME);
165
  SET ("gnu.classpath.home", PREFIX);
166
  // This is set to $(libdir) because we use this to find .security
167
  // files at runtime.
168
  char val2[sizeof ("file://") + sizeof (LIBDIR) + 1];
169
  strcpy (val2, "file://");
170
  strcat (val2, LIBDIR);
171
  SET ("gnu.classpath.home.url", val2);
172
 
173
  SET ("file.encoding", default_file_encoding);
174
 
175
#ifdef HAVE_UNAME
176
  struct utsname u;
177
  if (! uname (&u))
178
    {
179
      SET ("os.name", u.sysname);
180
      SET ("os.version", u.release);
181
 
182
      // Normalize x86 architecture names to "i386" (except on Windows, which 
183
      // is handled in win32.cc).
184
      if (u.machine[0] == 'i'
185
          && u.machine[1] != 0
186
          && u.machine[2] == '8'
187
          && u.machine[3] == '6'
188
          && u.machine[4] == 0)
189
        SET ("os.arch", "i386");
190
      else
191
        SET ("os.arch", u.machine);
192
    }
193
  else
194
    {
195
      SET ("os.name", "unknown");
196
      SET ("os.arch", "unknown");
197
      SET ("os.version", "unknown");
198
    }
199
#endif /* HAVE_UNAME */
200
 
201
#ifndef NO_GETUID
202
#ifdef HAVE_PWD_H
203
  uid_t user_id = getuid ();
204
  struct passwd *pwd_entry;
205
 
206
#ifdef HAVE_GETPWUID_R
207
  struct passwd pwd_r;
208
  size_t len_r = 200;
209
  char *buf_r = (char *) _Jv_AllocBytes (len_r);
210
 
211
  while (buf_r != NULL)
212
    {
213
      int r = getpwuid_adaptor (getpwuid_r, user_id, &pwd_r,
214
                                buf_r, len_r, &pwd_entry);
215
      if (r == 0)
216
        break;
217
      else if (r != ERANGE)
218
        {
219
          pwd_entry = NULL;
220
          break;
221
        }
222
      len_r *= 2;
223
      buf_r = (char *) _Jv_AllocBytes (len_r);
224
    }
225
#else
226
  pwd_entry = getpwuid (user_id);
227
#endif /* HAVE_GETPWUID_R */
228
 
229
  if (pwd_entry != NULL)
230
    {
231
      SET ("user.name", pwd_entry->pw_name);
232
      SET ("user.home", pwd_entry->pw_dir);
233
    }
234
#endif /* HAVE_PWD_H */
235
#endif /* NO_GETUID */
236
 
237
#ifdef HAVE_GETCWD
238
#ifdef HAVE_UNISTD_H
239
  /* Use getcwd to set "user.dir". */
240
  int buflen = 250;
241
  char *buffer = (char *) malloc (buflen);
242
  while (buffer != NULL)
243
    {
244
      if (getcwd (buffer, buflen) != NULL)
245
        {
246
          SET ("user.dir", buffer);
247
          break;
248
        }
249
      if (errno != ERANGE)
250
        break;
251
      buflen = 2 * buflen;
252
      buffer = (char *) realloc (buffer, buflen);
253
    }
254
  if (buffer != NULL)
255
    free (buffer);
256
#endif /* HAVE_UNISTD_H */
257
#endif /* HAVE_GETCWD */
258
 
259
  // Set user locale properties based on setlocale()
260
#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
261
  // We let the user choose the locale.  However, since Java differs
262
  // from POSIX, we arbitrarily pick LC_MESSAGES as determining the
263
  // Java locale.  We can't use LC_ALL because it might return a full
264
  // list of all the settings.  If we don't have LC_MESSAGES then we
265
  // just default to `en_US'.
266
  setlocale (LC_ALL, "");
267
  char *locale = setlocale (LC_MESSAGES, "");
268
  if (locale && strlen (locale) >= 2)
269
    {
270
      char buf[3];
271
      buf[2] = '\0';
272
      // copy the first two chars to user.language
273
      strncpy (buf, locale, 2);
274
      SET ("user.language", buf);
275
      // if the next char is a '_', copy the two after that to user.region
276
      locale += 2;
277
      if (locale[0] == '_')
278
        {
279
          locale++;
280
          strncpy (buf, locale, 2);
281
          SET ("user.region", buf);
282
        }
283
    }
284
  else
285
#endif /* HAVE_SETLOCALE and HAVE_LC_MESSAGES */
286
    {
287
      SET ("user.language", "en");
288
      SET ("user.region", "US");
289
    }
290
 
291
  // The java extensions directory.
292
  SET ("java.ext.dirs", JAVA_EXT_DIRS);
293
 
294
  // The endorsed directories that libgcj knows about by default.
295
  // This is a way to get other jars into the boot class loader
296
  // without overriding java.endorsed.dirs.
297
  SET ("gnu.gcj.runtime.endorsed.dirs", GCJ_ENDORSED_DIRS);
298
 
299
  // The path to libgcj's boot classes
300
  SET ("sun.boot.class.path", BOOT_CLASS_PATH);
301
 
302
  // If there is a default system database, set it.
303
  SET ("gnu.gcj.precompiled.db.path", LIBGCJ_DEFAULT_DATABASE);
304
 
305
  // Set some properties according to whatever was compiled in with
306
  // `-D'.  Important: after this point, the only properties that
307
  // should be set are those which either the user cannot meaningfully
308
  // override, or which augment whatever value the user has provided.
309
  for (int i = 0; i < _Jv_Properties_Count; ++i)
310
    {
311
      const char *s, *p;
312
      // Find the `='.
313
      for (s = p = _Jv_Compiler_Properties[i]; *s && *s != '='; ++s)
314
        ;
315
      jstring name = JvNewStringLatin1 (p, s - p);
316
      jstring val = JvNewStringLatin1 (*s == '=' ? s + 1 : s);
317
      newprops->put (name, val);
318
    }
319
 
320
  // Set the system properties from the user's environment.
321
#ifndef DISABLE_GETENV_PROPERTIES
322
  if (_Jv_Environment_Properties)
323
    {
324
      size_t i = 0;
325
 
326
      while (_Jv_Environment_Properties[i].key)
327
        {
328
          SET (_Jv_Environment_Properties[i].key,
329
               _Jv_Environment_Properties[i].value);
330
          i++;
331
        }
332
    }
333
#endif
334
 
335
  // The name used to invoke this process (argv[0] in C).
336
  SET ("gnu.gcj.progname", _Jv_GetSafeArg (0));
337
 
338
  // Allow platform specific settings and overrides.
339
  _Jv_platform_initProperties (newprops);
340
 
341
  // If java.library.path is set, tell libltdl so we search the new
342
  // directories as well.  FIXME: does this work properly on Windows?
343
  ::java::lang::String *path = newprops->getProperty(JvNewStringLatin1("java.library.path"));
344
  if (path)
345
    {
346
      char *val = (char *) _Jv_Malloc (JvGetStringUTFLength (path) + 1);
347
      jsize total = JvGetStringUTFRegion (path, 0, path->length(), val);
348
      val[total] = '\0';
349
      _Jv_SetDLLSearchPath (val);
350
      _Jv_Free (val);
351
    }
352
  else
353
    {
354
      // Set a value for user code to see.
355
#ifdef USE_LTDL
356
      char *libpath = getenv (LTDL_SHLIBPATH_VAR);
357
      if (libpath)
358
        newprops->put(JvNewStringLatin1 ("java.library.path"),
359
                      JvNewStringLatin1 (libpath));
360
      else
361
        SET ("java.library.path", "");
362
#else
363
      SET ("java.library.path", "");
364
#endif
365
    }
366
 
367
  // If java.class.path is still not set then set it according to the
368
  // CLASSPATH environment variable if given.  See gij.cc main () and
369
  // prims.cc _Jv_CreateJavaVM () for all the ways this could have
370
  // been set much earlier.
371
  // If CLASSPATH isn't set or if the path is empty fall back to "."
372
  path = newprops->getProperty(JvNewStringLatin1("java.class.path"));
373
  if (!path)
374
    {
375
      char *classpath = getenv("CLASSPATH");
376
      if (classpath && classpath[0] != 0)
377
        {
378
          path = JvNewStringLatin1 (classpath);
379
          newprops->put(JvNewStringLatin1 ("java.class.path"), path);
380
        }
381
    }
382
 
383
  if (!path || path->length() == 0)
384
    SET ("java.class.path", ".");
385
}
386
 
387
jboolean
388
gnu::classpath::SystemProperties::isWordsBigEndian (void)
389
{
390
  union
391
  {
392
    long lval;
393
    char cval;
394
  } u;
395
 
396
  u.lval = 1;
397
  return u.cval == 0;
398
}
399
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.