mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-12 17:12:40 +01:00
DroidFish: Implemented chmod using JNI. More efficient than starting a process.
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_petero_droidfish_engine_EngineUtil
|
* Class: org_petero_droidfish_engine_EngineUtil
|
||||||
@@ -30,3 +31,19 @@ extern "C" JNIEXPORT jint JNICALL Java_org_petero_droidfish_engine_EngineUtil_ge
|
|||||||
{
|
{
|
||||||
return sysconf(_SC_NPROCESSORS_ONLN);
|
return sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_petero_droidfish_engine_EngineUtil
|
||||||
|
* Method: chmod
|
||||||
|
* Signature: (Ljava/lang/String;)Z
|
||||||
|
*/
|
||||||
|
extern "C" JNIEXPORT jboolean JNICALL Java_org_petero_droidfish_engine_EngineUtil_chmod
|
||||||
|
(JNIEnv *env, jclass, jstring jExePath)
|
||||||
|
{
|
||||||
|
const char* exePath = (*env).GetStringUTFChars(jExePath, NULL);
|
||||||
|
if (!exePath)
|
||||||
|
return false;
|
||||||
|
bool ret = chmod(exePath, 0744) == 0;
|
||||||
|
(*env).ReleaseStringUTFChars(jExePath, exePath);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|||||||
@@ -43,4 +43,7 @@ public class EngineUtil {
|
|||||||
abi = "armeabi"; // Unknown ABI, assume original ARM
|
abi = "armeabi"; // Unknown ABI, assume original ARM
|
||||||
return "stockfish-" + abi;
|
return "stockfish-" + abi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Executes chmod 744 exePath. */
|
||||||
|
final static native boolean chmod(String exePath);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -240,12 +240,7 @@ public class ExternalEngine extends UCIEngineBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final void chmod(String exePath) throws IOException {
|
private final void chmod(String exePath) throws IOException {
|
||||||
Process proc = Runtime.getRuntime().exec(new String[]{"chmod", "744", exePath});
|
if (!EngineUtil.chmod(exePath))
|
||||||
try {
|
|
||||||
proc.waitFor();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
proc.destroy();
|
|
||||||
throw new IOException("chmod failed");
|
throw new IOException("chmod failed");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user