Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

timeval.h

00001 /*
00002  * timeval.h    1.3 2003/01/14
00003  *
00004  * Defines gettimeofday, timeval, etc. for Win32
00005  *
00006  * By Wu Yongwei
00007  *
00008  */
00009 
00010 #ifndef _TIMEVAL_H
00011 #define _TIMEVAL_H
00012 
00013 #ifdef _WIN32
00014 
00015 #define WIN32_LEAN_AND_MEAN
00016 #include <winsock2.h>
00017 #include <time.h>
00018 
00019 #if defined(_MSC_VER) || defined(__BORLANDC__)
00020 #define EPOCHFILETIME (116444736000000000i64)
00021 #else
00022 #define EPOCHFILETIME (116444736000000000LL)
00023 #endif
00024 
00025 struct timezone {
00026     int tz_minuteswest; /* minutes W of Greenwich */
00027     int tz_dsttime;     /* type of dst correction */
00028 };
00029 
00030 __inline int gettimeofday(struct timeval *tv, struct timezone *tz)
00031 {
00032     FILETIME        ft;
00033     LARGE_INTEGER   li;
00034     __int64         t;
00035     static int      tzflag;
00036 
00037     if (tv)
00038     {
00039         GetSystemTimeAsFileTime(&ft);
00040         li.LowPart  = ft.dwLowDateTime;
00041         li.HighPart = ft.dwHighDateTime;
00042         t  = li.QuadPart;       /* In 100-nanosecond intervals */
00043         t -= EPOCHFILETIME;     /* Offset to the Epoch time */
00044         t /= 10;                /* In microseconds */
00045         tv->tv_sec  = (long)(t / 1000000);
00046         tv->tv_usec = (long)(t % 1000000);
00047     }
00048 
00049     if (tz)
00050     {
00051         if (!tzflag)
00052         {
00053             _tzset();
00054             tzflag++;
00055         }
00056         tz->tz_minuteswest = _timezone / 60;
00057         tz->tz_dsttime = _daylight;
00058     }
00059 
00060     return 0;
00061 }
00062 
00063 #else  /* _WIN32 */
00064 
00065 #include <sys/time.h>
00066 
00067 #endif /* _WIN32 */
00068 
00069 #endif /* _TIMEVAL_H */

Generated on Tue Dec 13 19:44:50 2005 for GEOS by  doxygen 1.4.4