2007-10-11 21:39:21 +00:00
|
|
|
#include "math.h"
|
|
|
|
#include "stdlib.h"
|
2007-07-28 16:10:13 +00:00
|
|
|
#include "sys/time.h"
|
|
|
|
#include "time.h"
|
|
|
|
#include "time.h"
|
2007-07-07 23:47:35 +00:00
|
|
|
#include "string.h"
|
2007-09-12 01:13:05 +00:00
|
|
|
#include "stdio.h"
|
2007-10-23 17:22:48 +00:00
|
|
|
#include "stdint.h"
|
2007-06-25 01:34:07 +00:00
|
|
|
#include "jni.h"
|
2007-08-27 13:46:17 +00:00
|
|
|
#include "jni-util.h"
|
2007-06-25 01:34:07 +00:00
|
|
|
|
2007-10-23 17:22:48 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
# include "windows.h"
|
2007-10-24 16:24:02 +00:00
|
|
|
# define SO_PREFIX ""
|
|
|
|
#else
|
|
|
|
# define SO_PREFIX "lib"
|
|
|
|
#endif
|
|
|
|
|
2007-09-20 16:13:41 +00:00
|
|
|
#ifdef __APPLE__
|
2007-09-21 14:16:43 +00:00
|
|
|
# define SO_SUFFIX ".jnilib"
|
2007-10-24 16:24:02 +00:00
|
|
|
#elif defined WIN32
|
|
|
|
# define SO_SUFFIX ".dll"
|
2007-09-20 16:13:41 +00:00
|
|
|
#else
|
2007-09-21 14:16:43 +00:00
|
|
|
# define SO_SUFFIX ".so"
|
2007-09-20 16:13:41 +00:00
|
|
|
#endif
|
|
|
|
|
2007-07-07 23:47:35 +00:00
|
|
|
extern "C" JNIEXPORT jstring JNICALL
|
2007-10-26 18:13:21 +00:00
|
|
|
Java_java_lang_System_getProperty(JNIEnv* e, jclass, jstring name,
|
|
|
|
jbooleanArray found)
|
2007-07-07 23:47:35 +00:00
|
|
|
{
|
2007-10-26 18:13:21 +00:00
|
|
|
jstring r = 0;
|
|
|
|
const char* chars = e->GetStringUTFChars(name, 0);
|
|
|
|
if (chars) {
|
2007-10-24 16:24:02 +00:00
|
|
|
#ifdef WIN32
|
2007-10-26 18:13:21 +00:00
|
|
|
if (strcmp(chars, "line.separator") == 0) {
|
|
|
|
r = e->NewStringUTF("\r\n");
|
|
|
|
} else if (strcmp(chars, "file.separator") == 0) {
|
|
|
|
r = e->NewStringUTF("\\");
|
|
|
|
} else if (strcmp(chars, "os.name") == 0) {
|
|
|
|
r = e->NewStringUTF("windows");
|
|
|
|
} else if (strcmp(chars, "java.io.tmpdir") == 0) {
|
|
|
|
TCHAR buffer[MAX_PATH];
|
|
|
|
GetTempPath(MAX_PATH, buffer);
|
|
|
|
r = e->NewStringUTF(buffer);
|
|
|
|
} else if (strcmp(chars, "user.home") == 0) {
|
|
|
|
LPWSTR home = _wgetenv(L"USERPROFILE");
|
|
|
|
r = e->NewString(reinterpret_cast<jchar*>(home), lstrlenW(home));
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (strcmp(chars, "line.separator") == 0) {
|
|
|
|
r = e->NewStringUTF("\n");
|
|
|
|
} else if (strcmp(chars, "file.separator") == 0) {
|
|
|
|
r = e->NewStringUTF("/");
|
|
|
|
} else if (strcmp(chars, "os.name") == 0) {
|
|
|
|
r = e->NewStringUTF("posix");
|
|
|
|
} else if (strcmp(chars, "java.io.tmpdir") == 0) {
|
|
|
|
r = e->NewStringUTF("/tmp");
|
|
|
|
} else if (strcmp(chars, "user.home") == 0) {
|
|
|
|
r = e->NewStringUTF(getenv("HOME"));
|
|
|
|
}
|
|
|
|
#endif
|
2007-07-07 23:47:35 +00:00
|
|
|
|
2007-10-26 18:13:21 +00:00
|
|
|
e->ReleaseStringUTFChars(name, chars);
|
2007-10-24 15:44:51 +00:00
|
|
|
}
|
2007-09-13 00:21:37 +00:00
|
|
|
|
2007-10-26 18:13:21 +00:00
|
|
|
if (r) {
|
|
|
|
jboolean v = true;
|
|
|
|
e->SetBooleanArrayRegion(found, 0, 1, &v);
|
2007-10-24 15:44:51 +00:00
|
|
|
}
|
2007-10-24 16:24:02 +00:00
|
|
|
|
2007-10-26 18:13:21 +00:00
|
|
|
return r;
|
2007-07-07 23:47:35 +00:00
|
|
|
}
|
2007-07-28 16:10:13 +00:00
|
|
|
|
|
|
|
extern "C" JNIEXPORT jlong JNICALL
|
|
|
|
Java_java_lang_System_currentTimeMillis(JNIEnv*, jclass)
|
|
|
|
{
|
2007-10-23 17:22:48 +00:00
|
|
|
#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
|
2007-07-28 16:10:13 +00:00
|
|
|
timeval tv = { 0, 0 };
|
|
|
|
gettimeofday(&tv, 0);
|
|
|
|
return (static_cast<jlong>(tv.tv_sec) * 1000) +
|
|
|
|
(static_cast<jlong>(tv.tv_usec) / 1000);
|
2007-10-23 17:22:48 +00:00
|
|
|
#endif
|
2007-07-28 16:10:13 +00:00
|
|
|
}
|
2007-09-12 01:13:05 +00:00
|
|
|
|
|
|
|
extern "C" JNIEXPORT jstring JNICALL
|
|
|
|
Java_java_lang_System_doMapLibraryName(JNIEnv* e, jclass, jstring name)
|
|
|
|
{
|
|
|
|
jstring r = 0;
|
|
|
|
const char* chars = e->GetStringUTFChars(name, 0);
|
|
|
|
if (chars) {
|
|
|
|
unsigned nameLength = strlen(chars);
|
2007-10-24 16:24:02 +00:00
|
|
|
unsigned size = sizeof(SO_PREFIX) + nameLength + sizeof(SO_SUFFIX);
|
2007-09-12 01:13:05 +00:00
|
|
|
char buffer[size];
|
2007-10-24 16:24:02 +00:00
|
|
|
snprintf(buffer, size, SO_PREFIX "%s" SO_SUFFIX, chars);
|
2007-09-12 01:13:05 +00:00
|
|
|
r = e->NewStringUTF(buffer);
|
|
|
|
|
|
|
|
e->ReleaseStringUTFChars(name, chars);
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
2007-10-02 14:58:35 +00:00
|
|
|
|
2007-10-12 18:53:56 +00:00
|
|
|
extern "C" JNIEXPORT jdouble JNICALL
|
|
|
|
Java_java_lang_Math_sin(JNIEnv*, jclass, jdouble val)
|
|
|
|
{
|
|
|
|
return sin(val);
|
|
|
|
}
|
|
|
|
|
2007-10-11 22:41:52 +00:00
|
|
|
extern "C" JNIEXPORT jdouble JNICALL
|
|
|
|
Java_java_lang_Math_sqrt(JNIEnv*, jclass, jdouble val)
|
|
|
|
{
|
|
|
|
return sqrt(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT jdouble JNICALL
|
|
|
|
Java_java_lang_Math_pow(JNIEnv*, jclass, jdouble val, jdouble exp)
|
|
|
|
{
|
|
|
|
return pow(val, exp);
|
|
|
|
}
|
|
|
|
|
2007-10-11 15:59:22 +00:00
|
|
|
extern "C" JNIEXPORT jdouble JNICALL
|
|
|
|
Java_java_lang_Math_floor(JNIEnv*, jclass, jdouble val)
|
|
|
|
{
|
|
|
|
return floor(val);
|
|
|
|
}
|
|
|
|
|
2007-10-12 18:53:56 +00:00
|
|
|
extern "C" JNIEXPORT jdouble JNICALL
|
|
|
|
Java_java_lang_Math_ceil(JNIEnv*, jclass, jdouble val)
|
|
|
|
{
|
|
|
|
return ceil(val);
|
|
|
|
}
|
|
|
|
|
2007-10-02 14:58:35 +00:00
|
|
|
extern "C" JNIEXPORT jint JNICALL
|
2007-10-11 15:59:22 +00:00
|
|
|
Java_java_lang_Double_fillBufferWithDouble(JNIEnv* e, jclass, jdouble val,
|
2007-10-02 14:58:35 +00:00
|
|
|
jbyteArray buffer, jint bufferSize) {
|
2007-10-02 15:23:49 +00:00
|
|
|
jboolean isCopy;
|
|
|
|
jbyte* buf = e->GetByteArrayElements(buffer, &isCopy);
|
|
|
|
jint count = snprintf(reinterpret_cast<char*>(buf), bufferSize, "%g", val);
|
|
|
|
e->ReleaseByteArrayElements(buffer, buf, 0);
|
|
|
|
return count;
|
2007-10-02 14:58:35 +00:00
|
|
|
}
|