more system-specific tweaks for windows port

This commit is contained in:
Joel Dice
2007-10-24 10:24:02 -06:00
parent 0f1a9bc77e
commit 5bfd90cfed
4 changed files with 38 additions and 12 deletions

View File

@ -13,8 +13,16 @@
# include "windows.h" # include "windows.h"
#endif #endif
#ifdef __MINGW32__
# define SO_PREFIX ""
#else
# define SO_PREFIX "lib"
#endif
#ifdef __APPLE__ #ifdef __APPLE__
# define SO_SUFFIX ".jnilib" # define SO_SUFFIX ".jnilib"
#elif defined WIN32
# define SO_SUFFIX ".dll"
#else #else
# define SO_SUFFIX ".so" # define SO_SUFFIX ".so"
#endif #endif
@ -34,19 +42,20 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jint code)
}; };
switch (code) { switch (code) {
#ifdef WIN32
case LineSeparator: case LineSeparator:
return e->NewStringUTF("\n"); return e->NewStringUTF("\r\n");
case FileSeparator: case FileSeparator:
return e->NewStringUTF("/"); return e->NewStringUTF("\\");
#ifdef WIN32
case OsName: case OsName:
return e->NewStringUTF("Windows"); return e->NewStringUTF("Windows");
case JavaIoTmpdir: { case JavaIoTmpdir: {
TCHAR buffer[MAX_PATH]; TCHAR buffer[MAX_PATH];
GetTempPath(MAX_PATH, buffer); GetTempPath(MAX_PATH, buffer);
fprintf(stderr, "tmpdir: %s\n", buffer);
return e->NewStringUTF(buffer); return e->NewStringUTF(buffer);
} }
@ -55,6 +64,12 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jint code)
return e->NewString(reinterpret_cast<jchar*>(home), lstrlenW(home)); return e->NewString(reinterpret_cast<jchar*>(home), lstrlenW(home));
} }
#else #else
case LineSeparator:
return e->NewStringUTF("\n");
case FileSeparator:
return e->NewStringUTF("/");
case OsName: case OsName:
return e->NewStringUTF("posix"); return e->NewStringUTF("posix");
@ -109,9 +124,9 @@ Java_java_lang_System_doMapLibraryName(JNIEnv* e, jclass, jstring name)
const char* chars = e->GetStringUTFChars(name, 0); const char* chars = e->GetStringUTFChars(name, 0);
if (chars) { if (chars) {
unsigned nameLength = strlen(chars); unsigned nameLength = strlen(chars);
unsigned size = nameLength + 3 + sizeof(SO_SUFFIX); unsigned size = sizeof(SO_PREFIX) + nameLength + sizeof(SO_SUFFIX);
char buffer[size]; char buffer[size];
snprintf(buffer, size, "lib%s" SO_SUFFIX, chars); snprintf(buffer, size, SO_PREFIX "%s" SO_SUFFIX, chars);
r = e->NewStringUTF(buffer); r = e->NewStringUTF(buffer);
e->ReleaseStringUTFChars(name, chars); e->ReleaseStringUTFChars(name, chars);

View File

@ -1,6 +1,9 @@
package java.io; package java.io;
public class File { public class File {
private static final String FileSeparator
= System.getProperty("file.separator");
static { static {
System.loadLibrary("natives"); System.loadLibrary("natives");
} }
@ -13,15 +16,15 @@ public class File {
} }
public File(String parent, String child) { public File(String parent, String child) {
this(parent + "/" + child); this(parent + FileSeparator + child);
} }
public File(File parent, String child) { public File(File parent, String child) {
this(parent.getPath() + "/" + child); this(parent.getPath() + FileSeparator + child);
} }
public String getName() { public String getName() {
int index = path.lastIndexOf("/"); int index = path.lastIndexOf(FileSeparator);
if (index >= 0) { if (index >= 0) {
return path.substring(index + 1); return path.substring(index + 1);
} else { } else {
@ -34,7 +37,7 @@ public class File {
} }
public String getParent() { public String getParent() {
int index = path.lastIndexOf("/"); int index = path.lastIndexOf(FileSeparator);
if (index >= 0) { if (index >= 0) {
return path.substring(0, index); return path.substring(0, index);
} else { } else {

View File

@ -520,6 +520,8 @@ Java_java_lang_Runtime_load(Thread* t, jclass, jstring name, jboolean mapName)
} }
} }
fprintf(stderr, "load %s; map name: %d\n", n, mapName);
System::Library* lib; System::Library* lib;
if (LIKELY(t->m->system->success if (LIKELY(t->m->system->success
(t->m->system->load(&lib, n, mapName, t->m->libraries)))) (t->m->system->load(&lib, n, mapName, t->m->libraries))))

View File

@ -26,9 +26,15 @@
# error "Unsupported architecture" # error "Unsupported architecture"
#endif #endif
#ifdef __MINGW32__
# define SO_PREFIX ""
#else
# define SO_PREFIX "lib"
#endif
#ifdef __APPLE__ #ifdef __APPLE__
# define SO_SUFFIX ".jnilib" # define SO_SUFFIX ".jnilib"
#elseif defined __MINGW32__ #elif defined __MINGW32__
# define SO_SUFFIX ".dll" # define SO_SUFFIX ".dll"
#else #else
# define SO_SUFFIX ".so" # define SO_SUFFIX ".so"