From 6e32abbfc25930c079b643a85750472d50baac00 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 12 Jun 2002 17:01:02 +0000 Subject: [PATCH] re PR libgcj/6652 (new java.io.File("").getCanonicalFile() throws exception) * java/io/natFilePosix.cc (getCanonicalPath): Treat "" like ".". Fixes PR libgcj/6652. From-SVN: r54558 --- libjava/ChangeLog | 5 +++++ libjava/java/io/natFilePosix.cc | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 072c7b56945..26bd707ec6c 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,8 @@ +2002-06-12 Tom Tromey + + * java/io/natFilePosix.cc (getCanonicalPath): Treat "" like ".". + Fixes PR libgcj/6652. + 2002-06-10 Tom Tromey * java/lang/Class.h (Class::desiredAssertionStatus): Declare. diff --git a/libjava/java/io/natFilePosix.cc b/libjava/java/io/natFilePosix.cc index cd04571b04e..f9fe78ef203 100644 --- a/libjava/java/io/natFilePosix.cc +++ b/libjava/java/io/natFilePosix.cc @@ -104,9 +104,16 @@ java::io::File::attr (jint query) jstring java::io::File::getCanonicalPath (void) { - char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1); + // We use `+2' here because we might need to use `.' for our special + // case. + char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 2); char buf2[MAXPATHLEN]; jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf); + + // Special case: treat "" the same as ".". + if (total == 0) + buf[total++] = '.'; + buf[total] = '\0'; #ifdef HAVE_REALPATH