Reimplement misc. time functions

György 'Nog' Jeney nog at sdf.lonestar.org
Wed Dec 11 05:33:38 CST 2002


This patch removes win32/time.c

ChangeLog:
 * dlls/kernel/time.c
 * dlls/ntdll/Makefile.in
 * files/dos_fs.c
 * files/file.c
   - Reimplement time functions using ntdll functions.
   - Some cleanups

nog.

-------------- next part --------------
--- ../cleanwine/dlls/kernel/time.c	2002-12-11 08:17:05.000000000 +0200
+++ dlls/kernel/time.c	2002-12-11 12:30:32.000000000 +0200
@@ -1,5 +1,5 @@
 /*
- * Win32 kernel functions
+ * Win32 kernel time functions
  *
  * Copyright 1995 Martin von Loewis and Cameron Heide
  *
@@ -59,47 +59,17 @@
 BOOL WINAPI SetLocalTime(
     const SYSTEMTIME *systime) /* [in] The desired local time. */
 {
-    struct timeval tv;
-    struct tm t;
-    time_t sec;
-    time_t oldsec=time(NULL);
-    int err;
-
-    /* get the number of seconds */
-    t.tm_sec = systime->wSecond;
-    t.tm_min = systime->wMinute;
-    t.tm_hour = systime->wHour;
-    t.tm_mday = systime->wDay;
-    t.tm_mon = systime->wMonth - 1;
-    t.tm_year = systime->wYear - 1900;
-    t.tm_isdst = -1;
-    sec = mktime (&t);
-
-    /* set the new time */
-    tv.tv_sec = sec;
-    tv.tv_usec = systime->wMilliseconds * 1000;
-
-    /* error and sanity check*/
-    if( sec == (time_t)-1 || abs((int)(sec-oldsec)) > SETTIME_MAX_ADJUST ){
-        err = 1;
-        SetLastError(ERROR_INVALID_PARAMETER);
-    } else {
-#ifdef HAVE_SETTIMEOFDAY
-        err=settimeofday(&tv, NULL); /* 0 is OK, -1 is error */
-        if(err == 0)
-            return TRUE;
-        SetLastError(ERROR_PRIVILEGE_NOT_HELD);
-#else
-	err = 1;
-	SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-#endif
-    }
-    ERR("Cannot set time to %d/%d/%d %d:%d:%d Time adjustment %ld %s\n",
-            systime->wYear, systime->wMonth, systime->wDay, systime->wHour,
-            systime->wMinute, systime->wSecond,
-            sec-oldsec, err == -1 ? "No Permission" :
-                sec==(time_t)-1 ? "" : "is too large." );
-    return FALSE;
+    FILETIME ft;
+    LARGE_INTEGER st;
+    NTSTATUS status;
+
+    SystemTimeToFileTime( systime, &ft );
+
+    RtlLocalTimeToSystemTime( (PLARGE_INTEGER)&ft, &st );
+
+    if ((status = NtSetSystemTime(&st, NULL)))
+        SetLastError( RtlNtStatusToDosError(status) );
+    return !status;
 }
 
 
@@ -142,19 +112,10 @@
 BOOL WINAPI SetSystemTime(
     const SYSTEMTIME *systime) /* [in] The desired system time. */
 {
-    TIME_FIELDS tf;
     LARGE_INTEGER t;
     NTSTATUS status;
 
-    tf.Second = systime->wSecond;
-    tf.Minute = systime->wMinute;
-    tf.Hour = systime->wHour;
-    tf.Day = systime->wDay;
-    tf.Month = systime->wMonth;
-    tf.Year = systime->wYear;
-    tf.Milliseconds = systime->wMilliseconds;
-
-    RtlTimeFieldsToTime(&tf, &t);
+    SystemTimeToFileTime( systime, (PFILETIME)&t );
 
     if ((status = NtSetSystemTime(&t, NULL)))
         SetLastError( RtlNtStatusToDosError(status) );
@@ -496,3 +457,89 @@
         SetLastError( RtlNtStatusToDosError(status) );
     return !status;
 }
+
+/*********************************************************************
+ *      FileTimeToSystemTime                            (KERNEL32.@)
+ */
+BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
+{
+    TIME_FIELDS tf;
+
+    RtlTimeToTimeFields((PLARGE_INTEGER)ft, &tf);
+
+    syst->wYear = tf.Year;
+    syst->wMonth = tf.Month;
+    syst->wDay = tf.Day;
+    syst->wHour = tf.Hour;
+    syst->wMinute = tf.Minute;
+    syst->wSecond = tf.Second;
+    syst->wMilliseconds = tf.Milliseconds;
+    syst->wDayOfWeek = tf.Weekday;
+
+    return TRUE;
+}
+
+/*********************************************************************
+ *      SystemTimeToFileTime                            (KERNEL32.@)
+ */
+BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
+{
+    TIME_FIELDS tf;
+
+    tf.Year = syst->wYear;
+    tf.Month = syst->wMonth;
+    tf.Day = syst->wDay;
+    tf.Hour = syst->wHour;
+    tf.Minute = syst->wMinute;
+    tf.Second = syst->wSecond;
+    tf.Milliseconds = syst->wMilliseconds;
+
+    RtlTimeFieldsToTime(&tf, (PLARGE_INTEGER)&ft);
+
+    return TRUE;
+}
+
+/*********************************************************************
+ *      CompareFileTime                                 (KERNEL32.@)
+ */
+INT WINAPI CompareFileTime( LPFILETIME x, LPFILETIME y )
+{
+    if (!x || !y) return -1;
+
+    if (x->dwHighDateTime > y->dwHighDateTime)
+        return 1;
+    if (x->dwHighDateTime < y->dwHighDateTime)
+        return -1;
+    if (x->dwLowDateTime > y->dwLowDateTime)
+        return 1;
+    if (x->dwLowDateTime < y->dwLowDateTime)
+        return -1;
+    return 0;
+}
+
+/*********************************************************************
+ *      GetLocalTime                                    (KERNEL32.@)
+ */
+VOID WINAPI GetLocalTime(LPSYSTEMTIME systime)
+{
+    FILETIME lft;
+    LARGE_INTEGER ft;
+
+    NtQuerySystemTime(&ft);
+
+    RtlSystemTimeToLocalTime(&ft, (PLARGE_INTEGER)&lft);
+
+    FileTimeToSystemTime(&ft, systime);
+}
+
+/*********************************************************************
+ *      GetSystemTime                                   (KERNEL32.@)
+ */
+VOID WINAPI GetSystemTime(LPSYSTEMTIME systime)
+{
+    FILETIME ft;
+
+    NtQuerySystemTime((PLARGE_INTEGER)&ft);
+
+    FileTimeToSystemTime(&ft, systime);
+}
--- ../cleanwine/dlls/ntdll/Makefile.in	2002-11-28 19:30:35.000000000 +0200
+++ dlls/ntdll/Makefile.in	2002-12-11 12:31:48.000000000 +0200
@@ -72,7 +72,6 @@
 	$(TOPOBJDIR)/win32/except.c \
 	$(TOPOBJDIR)/win32/kernel32.c \
 	$(TOPOBJDIR)/win32/newfns.c \
-	$(TOPOBJDIR)/win32/time.c \
 	cdrom.c \
 	critsection.c \
 	debugtools.c \
--- ../cleanwine/files/dos_fs.c	2002-12-11 08:17:15.000000000 +0200
+++ files/dos_fs.c	2002-12-11 11:48:12.000000000 +0200
@@ -2481,25 +2481,6 @@
     return TRUE;
 }
 
-/***********************************************************************
- *           FileTimeToSystemTime   (KERNEL32.@)
- */
-BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
-{
-    struct tm *xtm;
-    DWORD remainder;
-    time_t xtime = DOSFS_FileTimeToUnixTime( ft, &remainder );
-    xtm = gmtime(&xtime);
-    syst->wYear         = xtm->tm_year+1900;
-    syst->wMonth        = xtm->tm_mon + 1;
-    syst->wDayOfWeek    = xtm->tm_wday;
-    syst->wDay	        = xtm->tm_mday;
-    syst->wHour	        = xtm->tm_hour;
-    syst->wMinute       = xtm->tm_min;
-    syst->wSecond       = xtm->tm_sec;
-    syst->wMilliseconds	= remainder / 10000;
-    return TRUE;
-}
 
 /***********************************************************************
  *           QueryDosDeviceA   (KERNEL32.@)
@@ -2562,41 +2543,6 @@
 
 
 /***********************************************************************
- *           SystemTimeToFileTime   (KERNEL32.@)
- */
-BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
-{
-#ifdef HAVE_TIMEGM
-    struct tm xtm;
-    time_t utctime;
-#else
-    struct tm xtm,*utc_tm;
-    time_t localtim,utctime;
-#endif
-
-    xtm.tm_year	= syst->wYear-1900;
-    xtm.tm_mon	= syst->wMonth - 1;
-    xtm.tm_wday	= syst->wDayOfWeek;
-    xtm.tm_mday	= syst->wDay;
-    xtm.tm_hour	= syst->wHour;
-    xtm.tm_min	= syst->wMinute;
-    xtm.tm_sec	= syst->wSecond; /* this is UTC */
-    xtm.tm_isdst = -1;
-#ifdef HAVE_TIMEGM
-    utctime = timegm(&xtm);
-    DOSFS_UnixTimeToFileTime( utctime, ft,
-			      syst->wMilliseconds * 10000 );
-#else
-    localtim = mktime(&xtm);    /* now we've got local time */
-    utc_tm = gmtime(&localtim);
-    utctime = mktime(utc_tm);
-    DOSFS_UnixTimeToFileTime( 2*localtim -utctime, ft,
-			      syst->wMilliseconds * 10000 );
-#endif
-    return TRUE;
-}
-
-/***********************************************************************
  *           DefineDosDeviceA       (KERNEL32.@)
  */
 BOOL WINAPI DefineDosDeviceA(DWORD flags,LPCSTR devname,LPCSTR targetpath) {
--- ../cleanwine/files/file.c	2002-11-30 10:47:39.000000000 +0200
+++ files/file.c	2002-12-11 12:18:40.000000000 +0200
@@ -1038,24 +1038,6 @@
 }
 
 /***********************************************************************
- *           CompareFileTime   (KERNEL32.@)
- */
-INT WINAPI CompareFileTime( LPFILETIME x, LPFILETIME y )
-{
-        if (!x || !y) return -1;
-
-	if (x->dwHighDateTime > y->dwHighDateTime)
-		return 1;
-	if (x->dwHighDateTime < y->dwHighDateTime)
-		return -1;
-	if (x->dwLowDateTime > y->dwLowDateTime)
-		return 1;
-	if (x->dwLowDateTime < y->dwLowDateTime)
-		return -1;
-	return 0;
-}
-
-/***********************************************************************
  *           FILE_GetTempFileName : utility for GetTempFileName
  */
 static UINT FILE_GetTempFileName( LPCWSTR path, LPCWSTR prefix, UINT unique,



More information about the wine-patches mailing list