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-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-09-20 16:13:41 +00:00
|
|
|
#ifdef __APPLE__
|
2007-09-21 14:16:43 +00:00
|
|
|
# define SO_SUFFIX ".jnilib"
|
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-06-29 16:42:39 +00:00
|
|
|
#undef JNIEXPORT
|
|
|
|
#define JNIEXPORT __attribute__ ((visibility("default")))
|
|
|
|
|
2007-07-07 23:47:35 +00:00
|
|
|
extern "C" JNIEXPORT jstring JNICALL
|
2007-08-27 13:46:17 +00:00
|
|
|
Java_java_lang_System_getProperty(JNIEnv* e, jclass, jint code)
|
2007-07-07 23:47:35 +00:00
|
|
|
{
|
2007-08-27 13:46:17 +00:00
|
|
|
enum {
|
|
|
|
LineSeparator = 100,
|
2007-09-13 00:21:37 +00:00
|
|
|
FileSeparator = 101,
|
|
|
|
OsName = 102,
|
2007-10-11 21:39:21 +00:00
|
|
|
JavaIoTmpdir = 103,
|
|
|
|
UserHome = 104
|
2007-08-27 13:46:17 +00:00
|
|
|
};
|
2007-07-07 23:47:35 +00:00
|
|
|
|
2007-08-27 13:46:17 +00:00
|
|
|
switch (code) {
|
|
|
|
case LineSeparator:
|
|
|
|
return e->NewStringUTF("\n");
|
|
|
|
|
2007-09-13 00:21:37 +00:00
|
|
|
case FileSeparator:
|
|
|
|
return e->NewStringUTF("/");
|
|
|
|
|
2007-08-27 13:46:17 +00:00
|
|
|
case OsName:
|
|
|
|
return e->NewStringUTF("posix");
|
2007-07-07 23:47:35 +00:00
|
|
|
|
2007-09-13 00:21:37 +00:00
|
|
|
case JavaIoTmpdir:
|
|
|
|
return e->NewStringUTF("/tmp");
|
|
|
|
|
2007-10-11 21:39:21 +00:00
|
|
|
case UserHome:
|
|
|
|
return e->NewStringUTF("/home/scharff");
|
|
|
|
#ifdef WIN32
|
|
|
|
LPWSTR home = _wgetenv(L"USERPROFILE");
|
|
|
|
return JvNewString(reinterpret_cast<jchar*>(home), lstrlenW(home));
|
|
|
|
#else
|
|
|
|
return e->NewStringUTF(getenv("HOME"));
|
|
|
|
#endif
|
2007-08-27 13:46:17 +00:00
|
|
|
default:
|
|
|
|
throwNew(e, "java/lang/RuntimeException", 0);
|
|
|
|
return 0;
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
timeval tv = { 0, 0 };
|
|
|
|
gettimeofday(&tv, 0);
|
|
|
|
return (static_cast<jlong>(tv.tv_sec) * 1000) +
|
|
|
|
(static_cast<jlong>(tv.tv_usec) / 1000);
|
|
|
|
}
|
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-09-20 16:13:41 +00:00
|
|
|
unsigned size = nameLength + 3 + sizeof(SO_SUFFIX);
|
2007-09-12 01:13:05 +00:00
|
|
|
char buffer[size];
|
2007-09-20 16:13:41 +00:00
|
|
|
snprintf(buffer, size, "lib%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-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-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
|
|
|
}
|