00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "GetTime.h"
00017
00018
00019
00020
00021 #if NR_PLATFORM == NR_PLATFORM_WIN32
00022 #if 0
00023 int gettimeofday(struct timeval* tv, void* placeholder)
00024 {
00025 union {
00026 long long ns100;
00027 FILETIME ft;
00028 } now;
00029
00030 GetSystemTimeAsFileTime (&now.ft);
00031 tv->tv_usec = (long) ((now.ns100 / 10LL) % 1000000LL);
00032 tv->tv_sec = (long) ((now.ns100 - 116444736000000000LL) / 10000000LL);
00033 printf("%d\n", tv->tv_sec);
00034
00035 return 0;
00036 }
00037 #endif
00038 #if 1
00039
00040
00041
00042
00043
00044
00045 #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) || defined(__WATCOMC__)
00046 #define DELTA_EPOCH_IN_USEC 11644473600000000Ui64
00047 #else
00048 #define DELTA_EPOCH_IN_USEC 11644473600000000ULL
00049 #endif
00050
00051 static nrEngine::uint64 filetime_to_unix_epoch (const FILETIME *ft)
00052 {
00053 nrEngine::uint64 res = (nrEngine::uint64) ft->dwHighDateTime << 32;
00054
00055 res |= ft->dwLowDateTime;
00056 res /= 10;
00057 res -= DELTA_EPOCH_IN_USEC;
00058 return (res);
00059 };
00060
00061 int gettimeofday (struct timeval *tv, void *tz)
00062 {
00063 FILETIME ft;
00064 nrEngine::uint64 tim;
00065
00066 if (!tv) {
00067 errno = EINVAL;
00068 return (-1);
00069 }
00070 GetSystemTimeAsFileTime (&ft);
00071 tim = filetime_to_unix_epoch (&ft);
00072 tv->tv_sec = (long) (tim / 1000000L);
00073 tv->tv_usec = (long) (tim % 1000000L);
00074
00075 return (0);
00076 }
00077
00078 #endif
00079
00080 #endif
00081
00082
00083