Update the implementations of gettimeofday() and localtime_r()
authorsherscher@apple.com <sherscher@apple.com@214c2c4a-bf3b-4dcf-9390-e4dd3010487d>
Fri, 23 Oct 2009 18:05:03 +0000 (18:05 +0000)
committersherscher@apple.com <sherscher@apple.com@214c2c4a-bf3b-4dcf-9390-e4dd3010487d>
Fri, 23 Oct 2009 18:05:03 +0000 (18:05 +0000)
git-svn-id: http://svn.macosforge.org/repository/mDNSResponder/trunk@6755 214c2c4a-bf3b-4dcf-9390-e4dd3010487d

mDNSWindows/PosixCompat.c

index 83175be..506c82b 100755 (executable)
@@ -93,34 +93,29 @@ inet_pton( int family, const char * addr, void * dst )
        }
     else return 0;
 }
-
+\r
 
 int
 gettimeofday( struct timeval * tv, struct timezone * tz )
-{
-#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
-#      define DELTA_EPOCH_IN_MICROSECS  11644473600000000Ui64
-#else
-#      define DELTA_EPOCH_IN_MICROSECS  11644473600000000ULL
-#endif
-       FILETIME ft;
-       unsigned __int64 tmpres = 0;
-       if ( tv != NULL )
-       {
-               GetSystemTimeAsFileTime(&ft);
-               tmpres |= ft.dwHighDateTime;
-               tmpres <<= 32;
-               tmpres |= ft.dwLowDateTime;
-               tmpres -= DELTA_EPOCH_IN_MICROSECS; 
-               tmpres /= 10;  /*convert into microseconds*/
-               tv->tv_sec = (long)(tmpres / 1000000UL);
-               tv->tv_usec = (long)(tmpres % 1000000UL);
-       }
+{\r
+#define EPOCHFILETIME (116444736000000000i64)\r
+\r
+       if ( tv != NULL )\r
+       {\r
+               FILETIME        ft;\r
+               LARGE_INTEGER   li;\r
+               __int64         t;\r
+\r
+               GetSystemTimeAsFileTime(&ft);\r
+               li.LowPart  = ft.dwLowDateTime;\r
+               li.HighPart = ft.dwHighDateTime;\r
+               t  = li.QuadPart;       /* In 100-nanosecond intervals */\r
+               t -= EPOCHFILETIME;     /* Offset to the Epoch time */\r
+               t /= 10;                        /* In microseconds */\r
+               tv->tv_sec  = ( long )( t / 1000000 );\r
+               tv->tv_usec = ( long )( t % 1000000 );\r
+       }\r
+\r
        return 0;
 }
 
@@ -128,6 +123,6 @@ gettimeofday( struct timeval * tv, struct timezone * tz )
 extern struct tm*
 localtime_r( const time_t * clock, struct tm * result )
 {
-       result = localtime( clock );
+       localtime_s( result, clock );
        return result;
 }