Added Process.getWorkingDirectory() and setWorkingDirectory() and posix implementation.

This commit is contained in:
Adam Murdoch
2013-01-26 17:51:10 +11:00
parent 47f914b49d
commit 64a738008e
9 changed files with 151 additions and 60 deletions

View File

@@ -144,6 +144,30 @@ Java_net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions_getPid(JNIEn
return getpid();
}
JNIEXPORT jstring JNICALL
Java_net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions_getWorkingDirectory(JNIEnv *env, jclass target, jobject result) {
char* path = getcwd(NULL, 0);
if (path == NULL) {
mark_failed_with_errno(env, "could not getcwd()", result);
return NULL;
}
jstring dir = char_to_java(env, path, result);
free(path);
return dir;
}
JNIEXPORT void JNICALL
Java_net_rubygrapefruit_platform_internal_jni_PosixProcessFunctions_setWorkingDirectory(JNIEnv *env, jclass target, jstring dir, jobject result) {
char* path = java_to_char(env, dir, result);
if (path == NULL) {
return;
}
if (chdir(path) != 0) {
mark_failed_with_errno(env, "could not setcwd()", result);
}
free(path);
}
/*
* Terminal functions
*/