6983520: java/io/pathNames/GeneralWin32.java fails with jdk7-b108 (win)
Reviewed-by: sherman
--- a/jdk/src/windows/native/java/io/WinNTFileSystem_md.c Tue Oct 12 08:49:33 2010 +0100
+++ b/jdk/src/windows/native/java/io/WinNTFileSystem_md.c Tue Oct 12 09:46:17 2010 +0100
@@ -815,7 +815,7 @@
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;
--- a/jdk/src/windows/native/java/io/io_util_md.c Tue Oct 12 08:49:33 2010 +0100
+++ b/jdk/src/windows/native/java/io/io_util_md.c Tue Oct 12 09:46:17 2010 +0100
@@ -66,6 +66,25 @@
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 @@
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);
--- a/jdk/src/windows/native/java/io/io_util_md.h Tue Oct 12 08:49:33 2010 +0100
+++ b/jdk/src/windows/native/java/io/io_util_md.h Tue Oct 12 09:46:17 2010 +0100
@@ -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);
--- a/jdk/test/java/io/pathNames/GeneralWin32.java Tue Oct 12 08:49:33 2010 +0100
+++ b/jdk/test/java/io/pathNames/GeneralWin32.java Tue Oct 12 09:46:17 2010 +0100
@@ -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