diff options
author | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-03-01 23:38:13 +0000 |
---|---|---|
committer | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-03-01 23:38:13 +0000 |
commit | d03da085bc50e83dbbf4ec4e29fdf17fa9973e6e (patch) | |
tree | 4cd6d3bffb8812360e139400a1ec89459ba0a0d9 /libjava/java/io/File.java | |
parent | b25365b4d3ea834d6c65c5893a85a7df172f56e9 (diff) | |
download | ppe42-gcc-d03da085bc50e83dbbf4ec4e29fdf17fa9973e6e.tar.gz ppe42-gcc-d03da085bc50e83dbbf4ec4e29fdf17fa9973e6e.zip |
2003-03-01 Ranjit Mathew <rmathew@hotmail.com>
* java/io/File (getAbsolutePath): Prefix drive specifier on
Windows for paths starting with a '\'.
(toURL): Make URL more consistent with what Sun's JDK returns.
* java/io/natFileWin32.cc (java::io::File::isAbsolute): Return
true only if the path is a UNC network path or it starts with a
drive specifier.
* java/net/URLStreamHandler.java (parseURL): Correct minor typo.
Be prepared to handle either '/' or '\\' in the file path for
Windows if using the "file" protocol.
Canonicalise the file path if using a relative path in the given
context and the "file" protocol.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@63635 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/io/File.java')
-rw-r--r-- | libjava/java/io/File.java | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/libjava/java/io/File.java b/libjava/java/io/File.java index 2086f1057aa..367fd44eb69 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 (); |