#include "sys/time.h" #include "time.h" #include "time.h" #include "string.h" #include "stdio.h" #include "jni.h" #include "jni-util.h" #undef JNIEXPORT #define JNIEXPORT __attribute__ ((visibility("default"))) extern "C" JNIEXPORT jstring JNICALL Java_java_lang_System_getProperty(JNIEnv* e, jclass, jint code) { enum { LineSeparator = 100, FileSeparator = 101, OsName = 102, JavaIoTmpdir = 103 }; switch (code) { case LineSeparator: return e->NewStringUTF("\n"); case FileSeparator: return e->NewStringUTF("/"); case OsName: return e->NewStringUTF("posix"); case JavaIoTmpdir: return e->NewStringUTF("/tmp"); default: throwNew(e, "java/lang/RuntimeException", 0); return 0; } } extern "C" JNIEXPORT jlong JNICALL Java_java_lang_System_currentTimeMillis(JNIEnv*, jclass) { timeval tv = { 0, 0 }; gettimeofday(&tv, 0); return (static_cast(tv.tv_sec) * 1000) + (static_cast(tv.tv_usec) / 1000); } 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); unsigned size = nameLength + 7; char buffer[size]; snprintf(buffer, size, "lib%s.so", chars); r = e->NewStringUTF(buffer); e->ReleaseStringUTFChars(name, chars); } return r; }