From 64c117c7840fbcecf7335f2fe7e421cc95f004a9 Mon Sep 17 00:00:00 2001 From: "mcs%netscape.com" Date: Fri, 21 Mar 2003 16:41:42 +0000 Subject: [PATCH] Fix 189089 - port nspr w32 now.c fix to directory. See bug # 188396 - NSPR should not use ftime on windows. This fixes a potential Year 2038 issue. --- directory/c-sdk/config/now.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/directory/c-sdk/config/now.c b/directory/c-sdk/config/now.c index 784b5ceabde..28beb7bef80 100644 --- a/directory/c-sdk/config/now.c +++ b/directory/c-sdk/config/now.c @@ -39,7 +39,9 @@ #include #elif defined(XP_UNIX) || defined(XP_OS2_EMX) || defined(XP_BEOS) #include -#elif defined(WIN32) || defined(XP_OS2_VACPP) +#elif defined(WIN32) +#include +#elif defined(XP_OS2_VACPP) #include #else #error "Architecture not supported" @@ -86,12 +88,20 @@ int main(int argc, char **argv) #elif defined(WIN32) __int64 now; - struct timeb b; - ftime(&b); - now = b.time; - now *= 1000000; - now += (1000 * b.millitm); + FILETIME ft; + GetSystemTimeAsFileTime(&ft); + CopyMemory(&now, &ft, sizeof(now)); + /* + * 116444736000000000 is the number of 100-nanosecond intervals + * between Jan. 1, 1601 and Jan. 1, 1970. + */ +#ifdef __GNUC__ + now = (now - 116444736000000000LL) / 10LL; + fprintf(stdout, "%lld", now); +#else + now = (now - 116444736000000000i64) / 10i64; fprintf(stdout, "%I64d", now); +#endif #elif defined(XP_OS2_VACPP) /* no long long or i64 so we use a string */