diff options
author | Jeroen Frijters <jeroen@frijters.net> | 2004-08-30 14:19:57 +0000 |
---|---|---|
committer | Andreas Tobler <andreast@gcc.gnu.org> | 2004-08-30 16:19:57 +0200 |
commit | 2c64dead9efc260f0c60d24960d463e56034e797 (patch) | |
tree | 395f94b22565caec425ef043fad9455eb7a70d37 /libjava/java/io | |
parent | 89b8abbf7d1d832e0597def81e243e47fc662cee (diff) | |
download | gcc-2c64dead9efc260f0c60d24960d463e56034e797.zip gcc-2c64dead9efc260f0c60d24960d463e56034e797.tar.gz gcc-2c64dead9efc260f0c60d24960d463e56034e797.tar.bz2 |
File.java File (String,String): Fixed handling of empty path.
2004-08-30 Jeroen Frijters <jeroen@frijters.net>
* java/io/File.java File(String,String): Fixed handling of empty
path.
From-SVN: r86774
Diffstat (limited to 'libjava/java/io')
-rw-r--r-- | libjava/java/io/File.java | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/libjava/java/io/File.java b/libjava/java/io/File.java index 1d930d5..2626d47 100644 --- a/libjava/java/io/File.java +++ b/libjava/java/io/File.java @@ -361,14 +361,37 @@ public class File implements Serializable, Comparable { if (name == null) throw new NullPointerException(); - if (dirPath != null && dirPath.length() > 0) + if (dirPath != null) { - // Try to be smart about the number of separator characters. - if (dirPath.charAt(dirPath.length() - 1) == separatorChar - || name.length() == 0) - path = normalizePath(dirPath + name); + if (dirPath.length() > 0) + { + // Try to be smart about the number of separator characters. + if (dirPath.charAt(dirPath.length() - 1) == separatorChar + || name.length() == 0) + path = normalizePath(dirPath + name); + else + path = normalizePath(dirPath + separatorChar + name); + } else - path = normalizePath(dirPath + separatorChar + name); + { + // If dirPath is empty, use a system dependant + // default prefix. + // Note that the leading separators in name have + // to be chopped off, to prevent them forming + // a UNC prefix on Windows. + if (separatorChar == '\\' /* TODO use ON_WINDOWS */) + { + int skip = 0; + while(name.length() > skip + && (name.charAt(skip) == separatorChar + || name.charAt(skip) == '/')) + { + skip++; + } + name = name.substring(skip); + } + path = normalizePath(separatorChar + name); + } } else path = normalizePath(name); |