Changeset 1391 for branches/GNU/src/gcc/libjava/java/lang/natSystem.cc
- Timestamp:
- Apr 27, 2004, 8:39:34 PM (22 years ago)
- Location:
- branches/GNU/src/gcc
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
libjava/java/lang/natSystem.cc (modified) (6 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gcc
- Property svn:ignore
-
old new 26 26 configure.vr 27 27 configure.vrs 28 28 29 Makefile 29 dir.info30 30 lost+found 31 31 update.out
-
- Property svn:ignore
-
branches/GNU/src/gcc/libjava/java/lang/natSystem.cc
-
Property cvs2svn:cvs-rev
changed from
1.1to1.1.1.2
r1390 r1391 1 1 // natSystem.cc - Native code implementing System class. 2 2 3 /* Copyright (C) 1998, 1999, 2000, 2001 , 2002Free Software Foundation3 /* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation 4 4 5 5 This file is part of libgcj. … … 10 10 11 11 #include <config.h> 12 12 13 13 14 #include <stdio.h> … … 15 16 #include <stdlib.h> 16 17 17 #include "platform.h"18 19 #ifdef HAVE_PWD_H20 #include <pwd.h>21 #endif22 #include <errno.h>23 24 #ifdef HAVE_UNAME25 #include <sys/utsname.h>26 #endif27 28 #ifdef HAVE_LOCALE_H29 #include <locale.h>30 #endif31 32 #ifdef HAVE_LANGINFO_H33 #include <langinfo.h>34 #endif35 36 #if TIME_WITH_SYS_TIME37 # include <sys/time.h>38 # include <time.h>39 #else40 # if HAVE_SYS_TIME_H41 # include <sys/time.h>42 # else43 # include <time.h>44 # endif45 #endif46 47 18 #include <gcj/cni.h> 48 19 #include <jvm.h> 49 #include <java-props.h>50 20 #include <java/lang/System.h> 51 21 #include <java/lang/Class.h> … … 53 23 #include <java/lang/ArrayIndexOutOfBoundsException.h> 54 24 #include <java/lang/NullPointerException.h> 55 #include <java/lang/StringBuffer.h>56 #include <java/util/Properties.h>57 #include <java/util/TimeZone.h>58 25 #include <java/io/PrintStream.h> 59 26 #include <java/io/InputStream.h> … … 63 30 64 31 void 65 java::lang::System::setErr (java::io::PrintStream *newErr)32 java::lang::System::setErr (java::io::PrintStream *newErr) 66 33 { 67 checkSetIO ();68 // This violates `final' semantics. Oh well.69 34 err = newErr; 70 35 } 71 36 72 37 void 73 java::lang::System::setIn (java::io::InputStream *newIn)38 java::lang::System::setIn (java::io::InputStream *newIn) 74 39 { 75 checkSetIO ();76 // This violates `final' semantics. Oh well.77 40 in = newIn; 78 41 } 79 42 80 43 void 81 java::lang::System::setOut (java::io::PrintStream *newOut)44 java::lang::System::setOut (java::io::PrintStream *newOut) 82 45 { 83 checkSetIO ();84 // This violates `final' semantics. Oh well.85 46 out = newOut; 86 47 } … … 169 130 } 170 131 171 #if ! defined (DEFAULT_FILE_ENCODING) && defined (HAVE_ICONV) \ 172 && defined (HAVE_NL_LANGINFO) 132 jboolean 133 java::lang::System::isWordsBigEndian (void) 134 { 135 union 136 { 137 long lval; 138 char cval; 139 } u; 173 140 174 static char * 175 file_encoding () 176 { 177 setlocale (LC_CTYPE, ""); 178 char *e = nl_langinfo (CODESET); 179 if (e == NULL || *e == '\0') 180 e = "8859_1"; 181 return e; 141 u.lval = 1; 142 return u.cval == 0; 182 143 } 183 184 #define DEFAULT_FILE_ENCODING file_encoding ()185 186 #endif187 188 #ifndef DEFAULT_FILE_ENCODING189 #define DEFAULT_FILE_ENCODING "8859_1"190 #endif191 192 static char *default_file_encoding = DEFAULT_FILE_ENCODING;193 194 #if HAVE_GETPWUID_R195 /* Use overload resolution to find out the signature of getpwuid_r. */196 197 /* This is Posix getpwuid_r. */198 template <typename T_uid, typename T_passwd, typename T_buf, typename T_len>199 static inline int200 getpwuid_adaptor(int (*getpwuid_r)(T_uid user_id, T_passwd *pwd_r,201 T_buf *buf_r, T_len len_r,202 T_passwd **pwd_entry_ptr),203 uid_t user_id, struct passwd *pwd_r,204 char *buf_r, size_t len_r, struct passwd **pwd_entry)205 {206 return getpwuid_r (user_id, pwd_r, buf_r, len_r, pwd_entry);207 }208 209 /* This is used on HPUX 10.20 */210 template <typename T_uid, typename T_passwd, typename T_buf, typename T_len>211 static inline int212 getpwuid_adaptor(int (*getpwuid_r)(T_uid user_id, T_passwd *pwd_r,213 T_buf *buf_r, T_len len_r),214 uid_t user_id, struct passwd *pwd_r,215 char *buf_r, size_t len_r, struct passwd **pwd_entry)216 {217 return getpwuid_r (user_id, pwd_r, buf_r, len_r);218 }219 220 /* This is used on IRIX 5.2. */221 template <typename T_uid, typename T_passwd, typename T_buf, typename T_len>222 static inline int223 getpwuid_adaptor(T_passwd * (*getpwuid_r)(T_uid user_id, T_passwd *pwd_r,224 T_buf *buf_r, T_len len_r),225 uid_t user_id, struct passwd *pwd_r,226 char *buf_r, size_t len_r, struct passwd **pwd_entry)227 {228 *pwd_entry = getpwuid_r (user_id, pwd_r, buf_r, len_r);229 return (*pwd_entry == NULL) ? errno : 0;230 }231 #endif232 233 /*234 * This method returns a time zone string that is used by init_properties235 * to set the default timezone property 'user.timezone'. That value is236 * used by default as a key into the timezone table used by the237 * java::util::TimeZone class.238 */239 jstring240 java::lang::System::getSystemTimeZone (void)241 {242 struct tm *tim;243 time_t current_time;244 long tzoffset;245 const char *tz1, *tz2;246 char *tzid;247 248 current_time = time(0);249 250 mktime(tim = localtime(¤t_time));251 #ifdef STRUCT_TM_HAS_GMTOFF252 // tm_gmtoff is secs EAST of UTC.253 tzoffset = -(tim->tm_gmtoff) + tim->tm_isdst * 3600L;254 #elif HAVE_TIMEZONE255 // timezone is secs WEST of UTC.256 tzoffset = timezone;257 #else258 // FIXME: there must be another global if neither tm_gmtoff nor timezone259 // is available, esp. if tzname is valid.260 // Richard Earnshaw <[email protected]> has suggested using difftime to261 // calculate between gmtime and localtime (and accounting for possible262 // daylight savings time) as an alternative.263 tzoffset = 0L;264 #endif265 266 #ifdef HAVE_TM_ZONE267 tz1 = tim->tm_zone;268 tz2 = "";269 #elif defined (HAVE_TZNAME)270 tz1 = tzname[0];271 tz2 = strcmp (tzname[0], tzname[1]) ? tzname[1] : "";272 #else273 // Some targets have no concept of timezones.274 tz1 = "???";275 tz2 = tz1;276 #endif277 278 if ((tzoffset % 3600) == 0)279 tzoffset = tzoffset / 3600;280 281 tzid = (char*) _Jv_Malloc (strlen(tz1) + strlen(tz2) + 6);282 sprintf(tzid, "%s%ld%s", tz1, tzoffset, tz2);283 jstring retval = JvNewStringUTF (tzid);284 _Jv_Free (tzid);285 286 return retval;287 }288 289 void290 java::lang::System::init_properties (void)291 {292 JvSynchronize sync (&java::lang::System::class$);293 294 if (properties != NULL)295 return;296 297 java::util::Properties* newprops = new java::util::Properties ();298 299 // A convenience define.300 #define SET(Prop,Val) \301 newprops->put(JvNewStringLatin1 (Prop), JvNewStringLatin1 (Val))302 303 // A mixture of the Java Product Versioning Specification304 // (introduced in 1.2), and earlier versioning properties.305 SET ("java.version", GCJVERSION);306 SET ("java.vendor", "Free Software Foundation, Inc.");307 SET ("java.vendor.url", "http://gcc.gnu.org/java/");308 SET ("java.class.version", "46.0");309 SET ("java.vm.specification.version", "1.0");310 SET ("java.vm.specification.name", "Java(tm) Virtual Machine Specification");311 SET ("java.vm.specification.vendor", "Sun Microsystems Inc.");312 SET ("java.vm.version", __VERSION__);313 SET ("java.vm.vendor", "Free Software Foundation, Inc.");314 SET ("java.vm.name", "GNU libgcj");315 SET ("java.specification.version", "1.3");316 SET ("java.specification.name", "Java(tm) Platform API Specification");317 SET ("java.specification.vendor", "Sun Microsystems Inc.");318 319 char value[100];320 #define NAME "GNU libgcj "321 strcpy (value, NAME);322 strncpy (value + sizeof (NAME) - 1, __VERSION__,323 sizeof(value) - sizeof(NAME));324 value[sizeof (value) - 1] = '\0';325 jstring version = JvNewStringLatin1 (value);326 newprops->put (JvNewStringLatin1 ("java.fullversion"), version);327 newprops->put (JvNewStringLatin1 ("java.vm.info"), version);328 329 // This definition is rather arbitrary: we choose $(prefix). In330 // part we do this because most people specify only --prefix and331 // nothing else when installing gcj. Plus, people are free to332 // redefine `java.home' with `-D' if necessary.333 SET ("java.home", PREFIX);334 335 SET ("file.encoding", default_file_encoding);336 337 #ifdef HAVE_UNAME338 struct utsname u;339 if (! uname (&u))340 {341 SET ("os.name", u.sysname);342 SET ("os.arch", u.machine);343 SET ("os.version", u.release);344 }345 else346 {347 SET ("os.name", "unknown");348 SET ("os.arch", "unknown");349 SET ("os.version", "unknown");350 }351 #endif /* HAVE_UNAME */352 353 #ifndef NO_GETUID354 #ifdef HAVE_PWD_H355 uid_t user_id = getuid ();356 struct passwd *pwd_entry;357 358 #ifdef HAVE_GETPWUID_R359 struct passwd pwd_r;360 size_t len_r = 200;361 char *buf_r = (char *) _Jv_AllocBytes (len_r);362 363 while (buf_r != NULL)364 {365 int r = getpwuid_adaptor (getpwuid_r, user_id, &pwd_r,366 buf_r, len_r, &pwd_entry);367 if (r == 0)368 break;369 else if (r != ERANGE)370 {371 pwd_entry = NULL;372 break;373 }374 len_r *= 2;375 buf_r = (char *) _Jv_AllocBytes (len_r);376 }377 #else378 pwd_entry = getpwuid (user_id);379 #endif /* HAVE_GETPWUID_R */380 381 if (pwd_entry != NULL)382 {383 SET ("user.name", pwd_entry->pw_name);384 SET ("user.home", pwd_entry->pw_dir);385 }386 #endif /* HAVE_PWD_H */387 #endif /* NO_GETUID */388 389 #ifdef HAVE_GETCWD390 #ifdef HAVE_UNISTD_H391 /* Use getcwd to set "user.dir". */392 int buflen = 250;393 char *buffer = (char *) malloc (buflen);394 while (buffer != NULL)395 {396 if (getcwd (buffer, buflen) != NULL)397 {398 SET ("user.dir", buffer);399 break;400 }401 if (errno != ERANGE)402 break;403 buflen = 2 * buflen;404 buffer = (char *) realloc (buffer, buflen);405 }406 if (buffer != NULL)407 free (buffer);408 #endif /* HAVE_UNISTD_H */409 #endif /* HAVE_GETCWD */410 411 // Set user locale properties based on setlocale()412 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)413 // We let the user choose the locale. However, since Java differs414 // from POSIX, we arbitrarily pick LC_MESSAGES as determining the415 // Java locale. We can't use LC_ALL because it might return a full416 // list of all the settings. If we don't have LC_MESSAGES then we417 // just default to `en_US'.418 setlocale (LC_ALL, "");419 char *locale = setlocale (LC_MESSAGES, "");420 if (locale && strlen (locale) >= 2)421 {422 char buf[3];423 buf[2] = '\0';424 // copy the first two chars to user.language425 strncpy (buf, locale, 2);426 SET ("user.language", buf);427 // if the next char is a '_', copy the two after that to user.region428 locale += 2;429 if (locale[0] == '_')430 {431 locale++;432 strncpy (buf, locale, 2);433 SET ("user.region", buf);434 }435 }436 else437 #endif /* HAVE_SETLOCALE and HAVE_LC_MESSAGES */438 {439 SET ("user.language", "en");440 SET ("user.region", "US");441 }442 443 // Set the "user.timezone" property.444 jstring timezone = getDefaultTimeZoneId ();445 if (timezone != NULL)446 newprops->put (JvNewStringLatin1 ("user.timezone"), timezone);447 448 // Set some properties according to whatever was compiled in with449 // `-D'.450 for (int i = 0; _Jv_Compiler_Properties[i]; ++i)451 {452 const char *s, *p;453 // Find the `='.454 for (s = p = _Jv_Compiler_Properties[i]; *s && *s != '='; ++s)455 ;456 jstring name = JvNewStringLatin1 (p, s - p);457 jstring val = JvNewStringLatin1 (*s == '=' ? s + 1 : s);458 newprops->put (name, val);459 }460 461 // Set the system properties from the user's environment.462 #ifndef DISABLE_GETENV_PROPERTIES463 if (_Jv_Environment_Properties)464 {465 size_t i = 0;466 467 while (_Jv_Environment_Properties[i].key)468 {469 SET (_Jv_Environment_Properties[i].key,470 _Jv_Environment_Properties[i].value);471 i++;472 }473 }474 #endif475 476 if (_Jv_Jar_Class_Path)477 newprops->put(JvNewStringLatin1 ("java.class.path"),478 JvNewStringLatin1 (_Jv_Jar_Class_Path));479 else480 {481 // FIXME: find libgcj.zip and append its path?482 char *classpath = ::getenv("CLASSPATH");483 jstring cp = newprops->getProperty (JvNewStringLatin1("java.class.path"));484 java::lang::StringBuffer *sb = new java::lang::StringBuffer ();485 486 if (classpath)487 {488 sb->append (JvNewStringLatin1 (classpath));489 #ifdef WIN32490 sb->append ((jchar) ';');491 #else492 sb->append ((jchar) ':');493 #endif494 }495 if (cp != NULL)496 sb->append (cp);497 else498 sb->append ((jchar) '.');499 500 newprops->put(JvNewStringLatin1 ("java.class.path"),501 sb->toString ());502 }503 504 // Allow platform specific settings and overrides.505 _Jv_platform_initProperties (newprops);506 507 // Finally, set the field. This ensures that concurrent getProperty()508 // calls will return initialized values without requiring them to be509 // synchronized in the common case.510 properties = newprops;511 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.
