This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: [PATCH]: adds missing System properties for gcj under mingw
- From: Adam King <aking at dreammechanics dot com>
- To: Bryce McKinlay <bryce at waitaki dot otago dot ac dot nz>
- Cc: java-patches at gcc dot gnu dot org, adam at xwt dot org
- Date: Sun, 7 Apr 2002 01:57:33 -0500
- Subject: Re: [PATCH]: adds missing System properties for gcj under mingw
- References: <20020406004521.B27004@dreammechanics.com> <3CAE9381.50803@waitaki.otago.ac.nz>
Bryce McKinlay wrote:
> It would be better if this code went in a new function in win32.cc, eg
> _Jv_platform_initProperties(). init_properties will call this function
> to initialize the platform-specific properties, and that way we'll avoid
> having too many #ifdefs in natSystem.cc.
> Other than that, if Adam M. likes it and you think its basically what
> the JDK does, then this patch is fine with me.
I've done as you suggested and created a new method
_Jv_platform_initProperties() which now sets the platform specific
System properties when called from init_properties. I also
saw another '#ifdef WIN32' in init_properties which I moved into
the new method. I'm still learning - so please let me know if there's
any other changes I need to make.
Adam
P.S. Should I add a small java program to the testsuite that checks
for the presence of all required System properties?
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
Index: java/lang/natSystem.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/lang/natSystem.cc,v
retrieving revision 1.48.2.3
diff -u -r1.48.2.3 natSystem.cc
--- java/lang/natSystem.cc 18 Mar 2002 06:30:24 -0000 1.48.2.3
+++ java/lang/natSystem.cc 7 Apr 2002 05:33:33 -0000
@@ -333,22 +333,6 @@
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 @@
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.
Index: include/win32.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/include/win32.h,v
retrieving revision 1.3.8.3
diff -u -r1.3.8.3 win32.h
--- include/win32.h 5 Apr 2002 04:22:53 -0000 1.3.8.3
+++ include/win32.h 7 Apr 2002 05:43:26 -0000
@@ -17,8 +17,10 @@
#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
Index: include/posix.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/include/posix.h,v
retrieving revision 1.3.2.2
diff -u -r1.3.2.2 posix.h
--- include/posix.h 10 Mar 2002 18:00:04 -0000 1.3.2.2
+++ include/posix.h 7 Apr 2002 05:44:52 -0000
@@ -31,10 +31,12 @@
#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)
Index: win32.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/win32.cc,v
retrieving revision 1.4.8.3
diff -u -r1.4.8.3 win32.cc
--- win32.cc 9 Mar 2002 22:33:15 -0000 1.4.8.3
+++ win32.cc 7 Apr 2002 05:45:56 -0000
@@ -11,9 +11,11 @@
#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 @@
// approximately 24 bytes per thread created.
return 0;
}
+
+// Platform specific setting of various 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;
+ }
+}
+
Index: posix.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/posix.cc,v
retrieving revision 1.3.2.3
diff -u -r1.3.2.3 posix.cc
--- posix.cc 9 Mar 2002 05:44:26 -0000 1.3.2.3
+++ posix.cc 7 Apr 2002 06:51:19 -0000
@@ -12,12 +12,14 @@
#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);
@@ -60,6 +62,23 @@
#else
signal (SIGPIPE, SIG_IGN);
#endif
+}
+
+// Platform specific setting of various 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