8055915: (ch) FileDispatcherImpl.truncate0 should use SetFileInformationByHandle [win]
Reviewed-by: alanb
--- a/jdk/src/java.base/windows/native/libnio/ch/FileDispatcherImpl.c Mon Mar 02 11:48:08 2015 +0900
+++ b/jdk/src/java.base/windows/native/libnio/ch/FileDispatcherImpl.c Mon Mar 02 11:07:47 2015 +0300
@@ -325,17 +325,14 @@
{
BOOL result = 0;
HANDLE h = (HANDLE)(handleval(env, fdo));
- LARGE_INTEGER offset;
+ FILE_END_OF_FILE_INFO eofInfo;
- offset.QuadPart = size;
- result = SetFilePointerEx(h, offset, NULL, FILE_BEGIN);
- if (result == 0) {
- JNU_ThrowIOExceptionWithLastError(env, "Truncation failed");
- return IOS_THROWN;
- }
-
- result = SetEndOfFile(h);
- if (result == 0) {
+ eofInfo.EndOfFile.QuadPart = size;
+ result = SetFileInformationByHandle(h,
+ FileEndOfFileInfo,
+ &eofInfo,
+ sizeof(eofInfo));
+ if (result == FALSE) {
JNU_ThrowIOExceptionWithLastError(env, "Truncation failed");
return IOS_THROWN;
}