mork work on the windows port

This commit is contained in:
Joel Dice
2007-10-23 11:22:48 -06:00
parent cb7189c5a7
commit 1381267e70
4 changed files with 128 additions and 66 deletions

View File

@ -5,9 +5,14 @@
#include "time.h"
#include "string.h"
#include "stdio.h"
#include "stdint.h"
#include "jni.h"
#include "jni-util.h"
#ifdef WIN32
# include "windows.h"
#endif
#ifdef __APPLE__
# define SO_SUFFIX ".jnilib"
#else
@ -41,14 +46,15 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jint code)
case JavaIoTmpdir:
return e->NewStringUTF("/tmp");
case UserHome:
return e->NewStringUTF("/home/scharff");
case UserHome: {
#ifdef WIN32
LPWSTR home = _wgetenv(L"USERPROFILE");
return JvNewString(reinterpret_cast<jchar*>(home), lstrlenW(home));
return e->NewString(reinterpret_cast<jchar*>(home), lstrlenW(home));
#else
return e->NewStringUTF(getenv("HOME"));
#endif
}
default:
throwNew(e, "java/lang/RuntimeException", 0);
return 0;
@ -58,10 +64,31 @@ Java_java_lang_System_getProperty(JNIEnv* e, jclass, jint code)
extern "C" JNIEXPORT jlong JNICALL
Java_java_lang_System_currentTimeMillis(JNIEnv*, jclass)
{
#ifdef WIN32
static LARGE_INTEGER frequency;
static LARGE_INTEGER time;
static bool init = true;
if (init) {
QueryPerformanceFrequency(&frequency);
if (frequency.QuadPart == 0) {
return 0;
}
init = false;
}
QueryPerformanceCounter(&time);
return static_cast<int64_t>
(((static_cast<double>(time.QuadPart)) * 1000.0) /
(static_cast<double>(frequency.QuadPart)));
#else
timeval tv = { 0, 0 };
gettimeofday(&tv, 0);
return (static_cast<jlong>(tv.tv_sec) * 1000) +
(static_cast<jlong>(tv.tv_usec) / 1000);
#endif
}
extern "C" JNIEXPORT jstring JNICALL