8055915: (ch) FileDispatcherImpl.truncate0 should use SetFileInformationByHandle [win]
authorigerasim
Mon, 02 Mar 2015 11:07:47 +0300
changeset 29228 dfa75715dfa7
parent 29227 2ef8d6233715
child 29229 522667854295
8055915: (ch) FileDispatcherImpl.truncate0 should use SetFileInformationByHandle [win] Reviewed-by: alanb
jdk/src/java.base/windows/native/libnio/ch/FileDispatcherImpl.c
--- 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;
     }