1
0
mirror of https://github.com/NekoX-Dev/NekoX.git synced 2024-12-15 12:29:26 +01:00
NekoX/TMessagesProj/jni/utilities.cpp

32 lines
943 B
C++
Raw Normal View History

2019-03-03 21:40:48 +01:00
#include <jni.h>
#include <sys/stat.h>
#include <climits>
#include <unistd.h>
2020-09-30 15:48:47 +02:00
#include <string>
2019-03-03 21:40:48 +01:00
thread_local static char buf[PATH_MAX + 1];
extern "C" JNIEXPORT jstring Java_org_telegram_messenger_Utilities_readlink(JNIEnv *env, jclass clazz, jstring path) {
const char *fileName = env->GetStringUTFChars(path, NULL);
ssize_t result = readlink(fileName, buf, PATH_MAX);
jstring value = 0;
if (result != -1) {
buf[result] = '\0';
value = env->NewStringUTF(buf);
}
env->ReleaseStringUTFChars(path, fileName);
return value;
}
2020-09-30 15:48:47 +02:00
extern "C" JNIEXPORT jstring Java_org_telegram_messenger_Utilities_readlinkFd(JNIEnv *env, jclass clazz, int fd) {
std::string path = "/proc/self/fd/";
path += fd;
ssize_t result = readlink(path.c_str(), buf, PATH_MAX);
jstring value = 0;
if (result != -1) {
buf[result] = '\0';
value = env->NewStringUTF(buf);
}
return value;
}