From 39bcf3ff5f12464e4ee7783df2d79a5e74003f5a Mon Sep 17 00:00:00 2001 From: Alan Bateman Date: Tue, 12 Oct 2010 09:46:17 +0100 Subject: [PATCH] 6983520: java/io/pathNames/GeneralWin32.java fails with jdk7-b108 (win) Reviewed-by: sherman --- .../native/java/io/WinNTFileSystem_md.c | 2 +- jdk/src/windows/native/java/io/io_util_md.c | 21 ++++++++++++++++++- jdk/src/windows/native/java/io/io_util_md.h | 1 + jdk/test/java/io/pathNames/GeneralWin32.java | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/jdk/src/windows/native/java/io/WinNTFileSystem_md.c b/jdk/src/windows/native/java/io/WinNTFileSystem_md.c index 10117e4aa03..633d20e578a 100644 --- a/jdk/src/windows/native/java/io/WinNTFileSystem_md.c +++ b/jdk/src/windows/native/java/io/WinNTFileSystem_md.c @@ -815,7 +815,7 @@ Java_java_io_WinNTFileSystem_getDriveDirectory(JNIEnv *env, jobject this, jint drive) { jstring ret = NULL; - jchar *p = _wgetdcwd(drive, NULL, MAX_PATH); + jchar *p = currentDir(drive); jchar *pf = p; if (p == NULL) return NULL; if (iswalpha(*p) && (p[1] == L':')) p += 2; diff --git a/jdk/src/windows/native/java/io/io_util_md.c b/jdk/src/windows/native/java/io/io_util_md.c index f5b9723a743..722913f775a 100644 --- a/jdk/src/windows/native/java/io/io_util_md.c +++ b/jdk/src/windows/native/java/io/io_util_md.c @@ -66,6 +66,25 @@ fileToNTPath(JNIEnv *env, jobject file, jfieldID id) { return pathToNTPath(env, path, JNI_FALSE); } +/* Returns the working directory for the given drive, or NULL */ +WCHAR* +currentDir(int di) { + UINT dt; + WCHAR root[4]; + // verify drive is valid as _wgetdcwd in the VC++ 2010 runtime + // library does not handle invalid drives. + root[0] = L'A' + (WCHAR)(di - 1); + root[1] = L':'; + root[2] = L'\\'; + root[3] = L'\0'; + dt = GetDriveTypeW(root); + if (dt == DRIVE_UNKNOWN || dt == DRIVE_NO_ROOT_DIR) { + return NULL; + } else { + return _wgetdcwd(di, NULL, MAX_PATH); + } +} + /* We cache the length of current working dir here to avoid calling _wgetcwd() every time we need to resolve a relative path. This piece of code needs to be revisited if chdir @@ -83,7 +102,7 @@ currentDirLength(const WCHAR* ps, int pathlen) { if ((d >= L'a') && (d <= L'z')) di = d - L'a' + 1; else if ((d >= L'A') && (d <= L'Z')) di = d - L'A' + 1; else return 0; /* invalid drive name. */ - dir = _wgetdcwd(di, NULL, MAX_PATH); + dir = currentDir(di); if (dir != NULL){ dirlen = wcslen(dir); free(dir); diff --git a/jdk/src/windows/native/java/io/io_util_md.h b/jdk/src/windows/native/java/io/io_util_md.h index c937adfbfb8..6b6b89b6397 100644 --- a/jdk/src/windows/native/java/io/io_util_md.h +++ b/jdk/src/windows/native/java/io/io_util_md.h @@ -33,6 +33,7 @@ WCHAR* pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE); WCHAR* fileToNTPath(JNIEnv *env, jobject file, jfieldID id); WCHAR* getPrefixed(const WCHAR* path, int pathlen); +WCHAR* currentDir(int di); int currentDirLength(const WCHAR* path, int pathlen); void fileOpen(JNIEnv *env, jobject this, jstring path, jfieldID fid, int flags); int handleAvailable(jlong fd, jlong *pbytes); diff --git a/jdk/test/java/io/pathNames/GeneralWin32.java b/jdk/test/java/io/pathNames/GeneralWin32.java index a43a8cd42f1..90802eee49f 100644 --- a/jdk/test/java/io/pathNames/GeneralWin32.java +++ b/jdk/test/java/io/pathNames/GeneralWin32.java @@ -22,7 +22,7 @@ */ /* @test - @bug 4032066 4039597 4046914 4054511 4065189 4109131 4875229 + @bug 4032066 4039597 4046914 4054511 4065189 4109131 4875229 6983520 @summary General exhaustive test of win32 pathname handling @author Mark Reinhold