Ignore:
Timestamp:
Apr 27, 2004, 8:39:34 PM (22 years ago)
Author:
bird
Message:

GCC v3.3.3 sources.

Location:
branches/GNU/src/gcc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/gcc

    • Property svn:ignore
      •  

        old new  
        2626configure.vr
        2727configure.vrs
         28
        2829Makefile
        29 dir.info
        3030lost+found
        3131update.out
  • branches/GNU/src/gcc/libjava/java/lang/natSystem.cc

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r1390 r1391  
    11// natSystem.cc - Native code implementing System class.
    22
    3 /* Copyright (C) 1998, 1999, 2000, 2001 , 2002 Free Software Foundation
     3/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
    44
    55   This file is part of libgcj.
     
    1010
    1111#include <config.h>
     12
    1213
    1314#include <stdio.h>
     
    1516#include <stdlib.h>
    1617
    17 #include "platform.h"
    18 
    19 #ifdef HAVE_PWD_H
    20 #include <pwd.h>
    21 #endif
    22 #include <errno.h>
    23 
    24 #ifdef HAVE_UNAME
    25 #include <sys/utsname.h>
    26 #endif
    27 
    28 #ifdef HAVE_LOCALE_H
    29 #include <locale.h>
    30 #endif
    31 
    32 #ifdef HAVE_LANGINFO_H
    33 #include <langinfo.h>
    34 #endif
    35 
    36 #if TIME_WITH_SYS_TIME
    37 # include <sys/time.h>
    38 # include <time.h>
    39 #else
    40 # if HAVE_SYS_TIME_H
    41 #  include <sys/time.h>
    42 # else
    43 #  include <time.h>
    44 # endif
    45 #endif
    46 
    4718#include <gcj/cni.h>
    4819#include <jvm.h>
    49 #include <java-props.h>
    5020#include <java/lang/System.h>
    5121#include <java/lang/Class.h>
     
    5323#include <java/lang/ArrayIndexOutOfBoundsException.h>
    5424#include <java/lang/NullPointerException.h>
    55 #include <java/lang/StringBuffer.h>
    56 #include <java/util/Properties.h>
    57 #include <java/util/TimeZone.h>
    5825#include <java/io/PrintStream.h>
    5926#include <java/io/InputStream.h>
     
    6330
    6431void
    65 java::lang::System::setErr (java::io::PrintStream *newErr)
     32java::lang::System::setErr (java::io::PrintStream *newErr)
    6633{
    67   checkSetIO ();
    68   // This violates `final' semantics.  Oh well.
    6934  err = newErr;
    7035}
    7136
    7237void
    73 java::lang::System::setIn (java::io::InputStream *newIn)
     38java::lang::System::setIn (java::io::InputStream *newIn)
    7439{
    75   checkSetIO ();
    76   // This violates `final' semantics.  Oh well.
    7740  in = newIn;
    7841}
    7942
    8043void
    81 java::lang::System::setOut (java::io::PrintStream *newOut)
     44java::lang::System::setOut (java::io::PrintStream *newOut)
    8245{
    83   checkSetIO ();
    84   // This violates `final' semantics.  Oh well.
    8546  out = newOut;
    8647}
     
    169130}
    170131
    171 #if ! defined (DEFAULT_FILE_ENCODING) && defined (HAVE_ICONV) \
    172     && defined (HAVE_NL_LANGINFO)
     132jboolean
     133java::lang::System::isWordsBigEndian (void)
     134{
     135  union
     136  {
     137    long lval;
     138    char cval;
     139  } u;
    173140
    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;
    182143}
    183 
    184 #define DEFAULT_FILE_ENCODING file_encoding ()
    185 
    186 #endif
    187 
    188 #ifndef DEFAULT_FILE_ENCODING
    189 #define DEFAULT_FILE_ENCODING "8859_1"
    190 #endif
    191 
    192 static char *default_file_encoding = DEFAULT_FILE_ENCODING;
    193 
    194 #if HAVE_GETPWUID_R
    195 /* 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 int
    200 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 int
    212 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 int
    223 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 #endif
    232 
    233 /*
    234  * This method returns a time zone string that is used by init_properties
    235  * to set the default timezone property 'user.timezone'.  That value is
    236  * used by default as a key into the timezone table used by the
    237  * java::util::TimeZone class.
    238  */
    239 jstring
    240 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(&current_time));
    251 #ifdef STRUCT_TM_HAS_GMTOFF
    252   // tm_gmtoff is secs EAST of UTC.
    253   tzoffset = -(tim->tm_gmtoff) + tim->tm_isdst * 3600L;
    254 #elif HAVE_TIMEZONE
    255   // timezone is secs WEST of UTC.
    256   tzoffset = timezone; 
    257 #else
    258   // FIXME: there must be another global if neither tm_gmtoff nor timezone
    259   // is available, esp. if tzname is valid.
    260   // Richard Earnshaw <[email protected]> has suggested using difftime to
    261   // calculate between gmtime and localtime (and accounting for possible
    262   // daylight savings time) as an alternative.
    263   tzoffset = 0L;
    264 #endif
    265 
    266 #ifdef HAVE_TM_ZONE
    267   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 #else
    273   // Some targets have no concept of timezones.
    274   tz1 = "???";
    275   tz2 = tz1;
    276 #endif
    277 
    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 void
    290 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 Specification
    304   // (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).  In
    330   // part we do this because most people specify only --prefix and
    331   // nothing else when installing gcj.  Plus, people are free to
    332   // redefine `java.home' with `-D' if necessary.
    333   SET ("java.home", PREFIX);
    334  
    335   SET ("file.encoding", default_file_encoding);
    336 
    337 #ifdef HAVE_UNAME
    338   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   else
    346     {
    347       SET ("os.name", "unknown");
    348       SET ("os.arch", "unknown");
    349       SET ("os.version", "unknown");
    350     }
    351 #endif /* HAVE_UNAME */
    352 
    353 #ifndef NO_GETUID
    354 #ifdef HAVE_PWD_H
    355   uid_t user_id = getuid ();
    356   struct passwd *pwd_entry;
    357 
    358 #ifdef HAVE_GETPWUID_R
    359   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 #else
    378   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_GETCWD
    390 #ifdef HAVE_UNISTD_H
    391   /* 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 differs
    414   // from POSIX, we arbitrarily pick LC_MESSAGES as determining the
    415   // Java locale.  We can't use LC_ALL because it might return a full
    416   // list of all the settings.  If we don't have LC_MESSAGES then we
    417   // 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.language
    425       strncpy (buf, locale, 2);
    426       SET ("user.language", buf);
    427       // if the next char is a '_', copy the two after that to user.region
    428       locale += 2;
    429       if (locale[0] == '_')
    430         {
    431           locale++;
    432           strncpy (buf, locale, 2);
    433           SET ("user.region", buf);
    434         }
    435     }
    436   else
    437 #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 with
    449   // `-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_PROPERTIES
    463   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 #endif
    475 
    476   if (_Jv_Jar_Class_Path)
    477     newprops->put(JvNewStringLatin1 ("java.class.path"),
    478                   JvNewStringLatin1 (_Jv_Jar_Class_Path));
    479   else
    480     {
    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 WIN32
    490           sb->append ((jchar) ';');
    491 #else
    492           sb->append ((jchar) ':');
    493 #endif
    494         }
    495       if (cp != NULL)
    496         sb->append (cp);
    497       else
    498         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 be
    509   // synchronized in the common case.
    510   properties = newprops;
    511 }
Note: See TracChangeset for help on using the changeset viewer.