Rob Shearman : ntdll: Remove the overly-cautious check which prevented NtSetSystemTime from changing the time by more than two minutes .

Alexandre Julliard julliard at wine.codeweavers.com
Mon Sep 10 10:18:02 CDT 2007


Module: wine
Branch: master
Commit: 67cc0302f441d648601ed63d8474887ba3d3a58b
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=67cc0302f441d648601ed63d8474887ba3d3a58b

Author: Rob Shearman <rob at codeweavers.com>
Date:   Fri Sep  7 18:41:42 2007 +0100

ntdll: Remove the overly-cautious check which prevented NtSetSystemTime from changing the time by more than two minutes.

Simplify the returning of different status codes by not playing around 
with the return value from settimeofday.

---

 dlls/ntdll/time.c |   37 ++++++++++++-------------------------
 1 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/dlls/ntdll/time.c b/dlls/ntdll/time.c
index 957d587..cd23958 100644
--- a/dlls/ntdll/time.c
+++ b/dlls/ntdll/time.c
@@ -62,8 +62,6 @@ static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
 };
 static RTL_CRITICAL_SECTION TIME_tz_section = { &critsect_debug, -1, 0, 0, 0, 0 };
 
-#define SETTIME_MAX_ADJUST 120
-
 #define TICKSPERSEC        10000000
 #define TICKSPERMSEC       10000
 #define SECSPERDAY         86400
@@ -898,7 +896,6 @@ NTSTATUS WINAPI NtSetSystemTime(const LARGE_INTEGER *NewTime, LARGE_INTEGER *Old
     time_t tm_t;
     DWORD sec, oldsec;
     LARGE_INTEGER tm;
-    int err;
 
     /* Return the old time if necessary */
     if (!OldTime) OldTime = &tm;
@@ -912,30 +909,20 @@ NTSTATUS WINAPI NtSetSystemTime(const LARGE_INTEGER *NewTime, LARGE_INTEGER *Old
     tv.tv_sec = sec;
     tv.tv_usec = 0;
 
-    /* error and sanity check*/
-    if(sec == (time_t)-1 || abs((int)(sec-oldsec)) > SETTIME_MAX_ADJUST) {
-        err = 2;
-    } else {
 #ifdef HAVE_SETTIMEOFDAY
-        err = settimeofday(&tv, NULL); /* 0 is OK, -1 is error */
-        if(err == 0)
-            return STATUS_SUCCESS;
-#else
-        err = 1;
-#endif
-    }
-
+    if (!settimeofday(&tv, NULL)) /* 0 is OK, -1 is error */
+        return STATUS_SUCCESS;
     tm_t = sec;
-    ERR("Cannot set time to %s Time adjustment %ld %s\n",
-        ctime( &tm_t ),
-            (long)(sec-oldsec),
-            err == -1 ? "No Permission"
-                      : sec == (time_t)-1 ? "" : "is too large." );
-
-    if(err == 2)
-        return STATUS_INVALID_PARAMETER;
-    else if(err == -1)
+    ERR("Cannot set time to %s, time adjustment %ld: %s\n",
+        ctime(&tm_t), (long)(sec-oldsec), strerror(errno));
+    if (errno == EPERM)
         return STATUS_PRIVILEGE_NOT_HELD;
     else
-        return STATUS_NOT_IMPLEMENTED;
+        return STATUS_INVALID_PARAMETER;
+#else
+    tm_t = sec;
+    FIXME("setting time to %s not implemented for missing settimeofday\n",
+        ctime(&tm_t));
+    return STATUS_NOT_IMPLEMENTED;
+#endif
 }




More information about the wine-cvs mailing list