GetTime.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   (c) Art Tevs, MPI Informatik Saarbruecken                             *
00004  *       mailto: <tevs@mpi-sb.mpg.de>                                      *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  ***************************************************************************/
00012 
00013 //----------------------------------------------------------------------------------
00014 // Includes
00015 //----------------------------------------------------------------------------------
00016 #include "GetTime.h"
00017 
00018 //namespace nrEngine{
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  * Number of micro-seconds between the beginning of the Windows epoch
00041  * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970).
00042  *
00043  * This assumes all Win32 compilers have 64-bit support.
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;                   /* from 100 nano-sec periods to usec */
00057     res -= DELTA_EPOCH_IN_USEC;  /* from Win epoch to Unix epoch */
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 //}; // end namespace   
00083 

Generated on Wed Sep 12 23:19:42 2007 for nrEngine by  doxygen 1.5.1