implement File.getAbsolutePath()/File.getAbsoluteFile() on Unix platforms

This commit is contained in:
Anonymous 2011-08-11 08:52:49 -06:00 committed by Joel Dice
parent 7ed580cf84
commit 3d7c65d314
2 changed files with 24 additions and 1 deletions

View File

@ -314,10 +314,29 @@ Java_java_io_File_toCanonicalPath(JNIEnv* /*e*/, jclass, jstring path)
}
extern "C" JNIEXPORT jstring JNICALL
Java_java_io_File_toAbsolutePath(JNIEnv* /*e*/, jclass, jstring path)
Java_java_io_File_toAbsolutePath(JNIEnv* e, jclass, jstring path)
{
#ifdef PLATFORM_WINDOWS
// todo
return path;
#else
jstring result = path;
string_t chars = getChars(e, path);
if (chars) {
if (chars[0] != '/') {
char* cwd = getcwd(NULL, 0);
if (cwd) {
unsigned size = strlen(cwd) + strlen(chars) + 2;
RUNTIME_ARRAY(char, buffer, size);
snprintf(RUNTIME_ARRAY_BODY(buffer), size, "%s/%s", cwd, chars);
result = e->NewStringUTF(RUNTIME_ARRAY_BODY(buffer));
free(cwd);
}
}
releaseChars(e, path, chars);
}
return result;
#endif
}
extern "C" JNIEXPORT jlong JNICALL

View File

@ -120,6 +120,10 @@ public class File implements Serializable {
return toAbsolutePath(path);
}
public File getAbsoluteFile() {
return new File(getAbsolutePath());
}
private static native long length(String path);
public long length() {