| 1 | #include <jni.h> |
| 2 | #include <sys/stat.h> |
| 3 | #include <climits> |
| 4 | #include <unistd.h> |
| 5 | |
| 6 | thread_local static char buf[PATH_MAX + 1]; |
| 7 | |
| 8 | extern "C" JNIEXPORT jstring Java_org_telegram_messenger_Utilities_readlink(JNIEnv *env, jclass clazz, jstring path) { |
| 9 | const char *fileName = env->GetStringUTFChars(path, NULL); |
| 10 | ssize_t result = readlink(fileName, buf, PATH_MAX); |
| 11 | jstring value = 0; |
| 12 | if (result != -1) { |
| 13 | buf[result] = '\0'; |
| 14 | value = env->NewStringUTF(buf); |
| 15 | } |
| 16 | env->ReleaseStringUTFChars(path, fileName); |
| 17 | return value; |
| 18 | } |
| 19 | |