8202076: test/jdk/java/io/File/WinSpecialFiles.java on windows with VS2017
Brian Burkhalter
brian.burkhalter at oracle.com
Thu May 17 00:56:41 UTC 2018
Hi Ivan,
On May 16, 2018, at 2:54 PM, Ivan Gerasimov <ivan.gerasimov at oracle.com> wrote:
> Maybe it is better to compare fileData.cFileName with the pathbuf to make sure we're dealing with the correct file?
Certainly making this change to the previous proposal would do no harm:
--- a/src/java.base/windows/native/libjava/WinNTFileSystem_md.c
+++ b/src/java.base/windows/native/libjava/WinNTFileSystem_md.c
@@ -541,10 +541,13 @@
WIN32_FIND_DATAW fileData;
HANDLE h = FindFirstFileW(pathbuf, &fileData);
if (h != INVALID_HANDLE_VALUE) {
- ULARGE_INTEGER length;
- length.LowPart = fileData.nFileSizeLow;
- length.HighPart = fileData.nFileSizeHigh;
- rv = (jlong)length.QuadPart;
+ size_t off = wcslen(pathbuf) - wcslen(fileData.cFileName);
+ if (wcscmp(pathbuf + off, fileData.cFileName) == 0) {
+ ULARGE_INTEGER length;
+ length.LowPart = fileData.nFileSizeLow;
+ length.HighPart = fileData.nFileSizeHigh;
+ rv = (jlong)length.QuadPart;
+ }
FindClose(h);
}
}
The offset in the string comparison is necessary as “C:\\pagefile.sys” becomes “pagefile.sys” in fileData.cFileName. I’m not certain that this will work in all cases however but it is certainly no worse than before.
Thanks for the suggestion!
Brian
More information about the core-libs-dev
mailing list