| 5 |
| #include <string> |
| 6 |
| 7 | thread_local static char buf[PATH_MAX + 1]; |
| 8 |
| 9 | extern "C" JNIEXPORT jstring Java_org_telegram_messenger_Utilities_readlink(JNIEnv *env, jclass clazz, jstring path) { |
| 10 | const char *fileName = env->GetStringUTFChars(path, NULL); |
| 11 | ssize_t result = readlink(fileName, buf, PATH_MAX); |
| 12 | jstring value = 0; |
| 13 | if (result != -1) { |
| 14 | buf[result] = '\0'; |
| 15 | value = env->NewStringUTF(buf); |
| 16 | } |
| 17 | env->ReleaseStringUTFChars(path, fileName); |
| 18 | return value; |
| 19 | } |
| 20 |
| 21 | extern "C" JNIEXPORT jstring Java_org_telegram_messenger_Utilities_readlinkFd(JNIEnv *env, jclass clazz, int fd) { |
| 22 | std::string path = "/proc/self/fd/"; |
| 23 | path += fd; |
| 24 | ssize_t result = readlink(path.c_str(), buf, PATH_MAX); |
| 25 | jstring value = 0; |
| 26 | if (result != -1) { |
| 27 | buf[result] = '\0'; |
| 28 | value = env->NewStringUTF(buf); |
| 29 | } |
| 30 | return value; |
| 31 | } |
| 32 |