From ca4e4fe34d2262bf39d04be993fa08d25aeb1a7b Mon Sep 17 00:00:00 2001
From: Duy Tran Khanh <40482367+khanhduytran0@users.noreply.github.com>
Date: Thu, 10 Jun 2021 18:36:56 +0700
Subject: [PATCH 11/37] Fixed Java_sun_nio_fs_UnixNativeDispatcher_futimes

---
 .../unix/native/libnio/fs/UnixNativeDispatcher.c      | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
index 76ab034bb..973870f9c 100644
--- a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
+++ b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
@@ -680,16 +680,17 @@ Java_sun_nio_fs_UnixNativeDispatcher_futimes0(JNIEnv* env, jclass this, jint fil
     jlong accessTime, jlong modificationTime)
 {
     struct timeval times[2];
+    struct timespec times2[2];
     int err = 0;
 
-    times[0].tv_sec = accessTime / 1000000;
+    times[0].tv_sec = times2[0].tv_sec = accessTime / 1000000;
     times[0].tv_usec = accessTime % 1000000;
 
-    times[1].tv_sec = modificationTime / 1000000;
+    times[1].tv_sec = times2[1].tv_sec = modificationTime / 1000000;
     times[1].tv_usec = modificationTime % 1000000;
 
-    times[0].tv_nsec = (accessTime % 1000000) * 1000;
-    times[1].tv_nsec = (modificationTime % 1000000) * 1000;
+    times2[0].tv_nsec = times[0].tv_usec * 1000;
+    times2[1].tv_nsec = times[1].tv_usec * 1000;
 
 #ifdef _ALLBSD_SOURCE
     RESTARTABLE(futimes(filedes, &times[0]), err);
@@ -701,7 +702,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_futimes0(JNIEnv* env, jclass this, jint fil
     if (my_futimesat_func != NULL) {
         RESTARTABLE((*my_futimesat_func)(filedes, NULL, &times[0]), err);
     } else {
-        RESTARTABLE((*my_utimensat_func)(filedes, NULL, &times[0], 0), err);
+        RESTARTABLE((*my_utimensat_func)(filedes, NULL, &times2[0], 0), err);
     }
 #endif
     if (err == -1) {
-- 
2.45.2

