aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam King <aking@dreammechanics.com>2002-04-07 11:27:00 +0000
committerBryce McKinlay <bryce@gcc.gnu.org>2002-04-07 12:27:00 +0100
commit455cd615c2dde26432ae38a5529a73789df52106 (patch)
tree069e876f78e2a8d34d5f4bb0c46db26f878a30bc
parent1abbe5b516d49d696910b03440f65c5819f8d755 (diff)
downloadgcc-455cd615c2dde26432ae38a5529a73789df52106.zip
gcc-455cd615c2dde26432ae38a5529a73789df52106.tar.gz
gcc-455cd615c2dde26432ae38a5529a73789df52106.tar.bz2
natSystem.cc (init_properties): Call new function _Jv_platform_initProperties.
2002-04-07 Adam King <aking@dreammechanics.com> * java/lang/natSystem.cc (init_properties): Call new function _Jv_platform_initProperties. * win32 (_Jv_platform_initProperties): New function that adds Win32 support for the System properties os.name, os.arch, os.version, user.name, user.home, and user.dir. * include/posix.h, include/win32.h, posix.cc: New function _Jv_platform_initProperties. From-SVN: r51989
-rw-r--r--libjava/ChangeLog10
-rw-r--r--libjava/include/posix.h2
-rw-r--r--libjava/include/win32.h2
-rw-r--r--libjava/java/lang/natSystem.cc20
-rw-r--r--libjava/posix.cc19
-rw-r--r--libjava/win32.cc130
6 files changed, 167 insertions, 16 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index d3fd682..e29b4d2 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,13 @@
+2002-04-07 Adam King <aking@dreammechanics.com>
+
+ * java/lang/natSystem.cc (init_properties): Call new function
+ _Jv_platform_initProperties.
+ * win32 (_Jv_platform_initProperties): New function that adds Win32
+ support for the System properties os.name, os.arch, os.version,
+ user.name, user.home, and user.dir.
+ * include/posix.h, include/win32.h, posix.cc: New function
+ _Jv_platform_initProperties.
+
2002-04-06 Mark Wielaard <mark@klomp.org>
* java/lang/Character,java (isDefined): getType() != UNASSIGNED.
diff --git a/libjava/include/posix.h b/libjava/include/posix.h
index 7e9aaf5..8fa782f 100644
--- a/libjava/include/posix.h
+++ b/libjava/include/posix.h
@@ -34,10 +34,12 @@ details. */
#include <fcntl.h>
#include <gcj/cni.h>
+#include <java/util/Properties.h>
extern int _Jv_select (int n, fd_set *, fd_set *, fd_set *, struct timeval *);
extern jlong _Jv_platform_gettimeofday ();
extern void _Jv_platform_initialize (void);
+extern void _Jv_platform_initProperties (java::util::Properties*);
inline void
_Jv_platform_close_on_exec (jint fd)
diff --git a/libjava/include/win32.h b/libjava/include/win32.h
index 9d8bdfb..9a8a769 100644
--- a/libjava/include/win32.h
+++ b/libjava/include/win32.h
@@ -17,8 +17,10 @@ details. */
#undef __INSIDE_CYGWIN__
#include <winsock.h>
#include <gcj/cni.h>
+#include <java/util/Properties.h>
extern void _Jv_platform_initialize (void);
+extern void _Jv_platform_initProperties (java::util::Properties*);
extern jlong _Jv_platform_gettimeofday ();
inline void
diff --git a/libjava/java/lang/natSystem.cc b/libjava/java/lang/natSystem.cc
index 958e78c..b8467f2 100644
--- a/libjava/java/lang/natSystem.cc
+++ b/libjava/java/lang/natSystem.cc
@@ -333,22 +333,6 @@ java::lang::System::init_properties (void)
SET ("file.encoding", default_file_encoding);
-#ifdef WIN32
- SET ("file.separator", "\\");
- SET ("path.separator", ";");
- SET ("line.separator", "\r\n");
- SET ("java.io.tmpdir", "C:\\temp");
-#else
- // Unix.
- SET ("file.separator", "/");
- SET ("path.separator", ":");
- SET ("line.separator", "\n");
- char *tmpdir = ::getenv("TMPDIR");
- if (! tmpdir)
- tmpdir = "/tmp";
- SET ("java.io.tmpdir", tmpdir);
-#endif
-
#ifdef HAVE_UNAME
struct utsname u;
if (! uname (&u))
@@ -515,6 +499,10 @@ java::lang::System::init_properties (void)
newprops->put(JvNewStringLatin1 ("java.class.path"),
sb->toString ());
}
+
+ // Allow platform specific settings and overrides.
+ _Jv_platform_initProperties (newprops);
+
// Finally, set the field. This ensures that concurrent getProperty()
// calls will return initialized values without requiring them to be
// synchronized in the common case.
diff --git a/libjava/posix.cc b/libjava/posix.cc
index 6b0ea8c..ebff1c9 100644
--- a/libjava/posix.cc
+++ b/libjava/posix.cc
@@ -12,12 +12,14 @@ details. */
#include "posix.h"
+#include <stdlib.h>
#include <errno.h>
#include <signal.h>
#include <jvm.h>
#include <java/lang/Thread.h>
#include <java/io/InterruptedIOException.h>
+#include <java/util/Properties.h>
#if defined (ECOS)
extern "C" unsigned long long _clock (void);
@@ -62,6 +64,23 @@ _Jv_platform_initialize (void)
#endif
}
+// Set platform-specific System properties.
+void
+_Jv_platform_initProperties (java::util::Properties* newprops)
+{
+ // A convenience define.
+#define SET(Prop,Val) \
+ newprops->put(JvNewStringLatin1 (Prop), JvNewStringLatin1 (Val))
+
+ SET ("file.separator", "/");
+ SET ("path.separator", ":");
+ SET ("line.separator", "\n");
+ char *tmpdir = ::getenv("TMPDIR");
+ if (! tmpdir)
+ tmpdir = "/tmp";
+ SET ("java.io.tmpdir", tmpdir);
+}
+
static inline void
internal_gettimeofday (struct timeval *result)
{
diff --git a/libjava/win32.cc b/libjava/win32.cc
index 57c6378..78f57b3 100644
--- a/libjava/win32.cc
+++ b/libjava/win32.cc
@@ -11,9 +11,11 @@ details. */
#include <config.h>
#include <jvm.h>
#include <sys/timeb.h>
+#include <stdlib.h>
#include "platform.h"
#include <java/lang/ArithmeticException.h>
+#include <java/util/Properties.h>
static LONG CALLBACK
win32_exception_handler (LPEXCEPTION_POINTERS e)
@@ -62,3 +64,131 @@ __mingwthr_key_dtor (DWORD, void (*) (void *))
// approximately 24 bytes per thread created.
return 0;
}
+
+// Set platform-specific System properties.
+void
+_Jv_platform_initProperties (java::util::Properties* newprops)
+{
+ // A convenience define.
+#define SET(Prop,Val) \
+ newprops->put(JvNewStringLatin1 (Prop), JvNewStringLatin1 (Val))
+
+ SET ("file.separator", "\\");
+ SET ("path.separator", ";");
+ SET ("line.separator", "\r\n");
+ SET ("java.io.tmpdir", "C:\\temp");
+
+ // Use GetCurrentDirectory to set 'user.dir'.
+ DWORD buflen = MAX_PATH;
+ char* buffer = (char *) malloc (buflen);
+ if (buffer != NULL)
+ {
+ if (GetCurrentDirectory (buflen, buffer))
+ SET ("user.dir", buffer);
+ free (buffer);
+ }
+
+ // Use GetUserName to set 'user.name'.
+ buflen = 257; // UNLEN + 1
+ buffer = (char *) malloc (buflen);
+ if (buffer != NULL)
+ {
+ if (GetUserName (buffer, &buflen))
+ SET ("user.name", buffer);
+ free (buffer);
+ }
+
+ // According to the api documentation for 'GetWindowsDirectory()', the
+ // environmental variable HOMEPATH always specifies the user's home
+ // directory or a default directory. On the 3 windows machines I checked
+ // only 1 had it set. If it's not set, JDK1.3.1 seems to set it to
+ // the windows directory, so we'll do the same.
+ char* userHome = NULL;
+ if ((userHome = ::getenv( "HOMEPATH" )) == NULL )
+ {
+ // Check HOME since it's what I use.
+ if ((userHome = ::getenv( "HOME" )) == NULL )
+ {
+ // Not found - use the windows directory like JDK1.3.1 does.
+ char* winHome = (char *)malloc (MAX_PATH);
+ if ( winHome != NULL )
+ {
+ if (GetWindowsDirectory (winHome, MAX_PATH))
+ SET ("user.home", winHome);
+ free (winHome);
+ }
+ }
+ }
+ if( userHome != NULL )
+ SET ("user.home", userHome);
+
+ // Get and set some OS info.
+ OSVERSIONINFO osvi;
+ ZeroMemory (&osvi, sizeof(OSVERSIONINFO));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ if (GetVersionEx (&osvi))
+ {
+ char *buffer = (char *) malloc (30);
+ if (buffer != NULL)
+ {
+ sprintf (buffer, "%d.%d", (int)osvi.dwMajorVersion, (int)osvi.dwMinorVersion);
+ SET ("os.version", buffer);
+ free (buffer);
+ }
+
+ switch (osvi.dwPlatformId)
+ {
+ case VER_PLATFORM_WIN32_WINDOWS:
+ if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
+ SET ("os.name", "Windows 95");
+ else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
+ SET ("os.name", "Windows 98");
+ else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
+ SET ("os.name", "Windows Me");
+ else
+ SET ("os.name", "Windows ??");
+ break;
+
+ case VER_PLATFORM_WIN32_NT:
+ if (osvi.dwMajorVersion <= 4 )
+ SET ("os.name", "Windows NT");
+ else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
+ SET ("os.name", "Windows 2000");
+ else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
+ SET ("os.name", "Windows XP");
+ else
+ SET ("os.name", "Windows NT ??");
+ break;
+
+ default:
+ SET ("os.name", "Windows UNKNOWN");
+ break;
+ }
+ }
+
+ // Set the OS architecture.
+ SYSTEM_INFO si;
+ GetSystemInfo (&si);
+ switch( si.dwProcessorType )
+ {
+ case PROCESSOR_INTEL_386:
+ SET ("os.arch", "i386");
+ break;
+ case PROCESSOR_INTEL_486:
+ SET ("os.arch", "i486");
+ break;
+ case PROCESSOR_INTEL_PENTIUM:
+ SET ("os.arch", "i586");
+ break;
+ case PROCESSOR_MIPS_R4000:
+ SET ("os.arch", "MIPS4000");
+ break;
+ case PROCESSOR_ALPHA_21064:
+ SET ("os.arch", "ALPHA");
+ break;
+ default:
+ SET ("os.arch", "unknown");
+ break;
+ }
+}
+