diff options
Diffstat (limited to 'libjava/java/io')
-rw-r--r-- | libjava/java/io/File.java | 24 | ||||
-rw-r--r-- | libjava/java/io/natFileWin32.cc | 9 |
2 files changed, 26 insertions, 7 deletions
diff --git a/libjava/java/io/File.java b/libjava/java/io/File.java index 2086f10..367fd44 100644 --- a/libjava/java/io/File.java +++ b/libjava/java/io/File.java @@ -1,6 +1,6 @@ // File.java - File name -/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation +/* Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. This file is part of libgcj. @@ -153,12 +153,20 @@ public class File implements Serializable, Comparable this (dir == null ? null : dir.path, name); } - // FIXME ??? public String getAbsolutePath () { if (isAbsolute ()) return path; - return System.getProperty("user.dir") + separatorChar + path; + else if (separatorChar == '\\' + && path.length () > 0 && path.charAt (0) == '\\') + { + // On Windows, even if the path starts with a '\\' it is not + // really absolute until we prefix the drive specifier from + // the current working directory to it. + return System.getProperty ("user.dir").substring (0, 2) + path; + } + else + return System.getProperty ("user.dir") + separatorChar + path; } /** @since 1.2 */ @@ -289,8 +297,14 @@ public class File implements Serializable, Comparable public URL toURL () throws MalformedURLException { - return new URL ("file://" + getAbsolutePath () - + (isDirectory() ? "/" : "")); + // On Win32, Sun's JDK returns URLs of the form "file:/c:/foo/bar.txt", + // while on UNIX, it returns URLs of the form "file:/foo/bar.txt". + if (separatorChar == '\\') + return new URL ("file:/" + getAbsolutePath ().replace ('\\', '/') + + (isDirectory() ? "/" : "")); + else + return new URL ("file:" + getAbsolutePath () + + (isDirectory() ? "/" : "")); } private final native boolean performMkdir (); diff --git a/libjava/java/io/natFileWin32.cc b/libjava/java/io/natFileWin32.cc index 5245feb5..9029881 100644 --- a/libjava/java/io/natFileWin32.cc +++ b/libjava/java/io/natFileWin32.cc @@ -119,9 +119,14 @@ java::io::File::getCanonicalPath (void) jboolean java::io::File::isAbsolute (void) { - if (path->length() > 0 - && (path->charAt(0) == '/' || path->charAt(0) == '\\')) + // See if the path represents a Windows UNC network path. + if (path->length () > 1 + && (path->charAt (0) == '\\') && (path->charAt (1) == '\\')) return true; + + // Note that the path is not an absolute path even if it starts with + // a '/' or a '\' because it lacks a drive specifier. + if (path->length() < 3) return false; // Hard-code A-Za-z because Windows (I think) can't use non-ASCII |