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

timeval.h

00001 /**********************************************************************
00002  * $Id: timeval.h 2147 2008-08-07 16:57:25Z pramsey $
00003  *
00004  * GEOS - Geometry Engine Open Source
00005  * http://geos.refractions.net
00006  *
00007  * Copyright (C) 2006 Wu Yongwei
00008  *
00009  * This is free software; you can redistribute and/or modify it under
00010  * the terms of the GNU Lesser General Public Licence as published
00011  * by the Free Software Foundation. 
00012  * See the COPYING file for more information.
00013  *
00014  **********************************************************************/
00015 
00016 
00017 #ifndef _TIMEVAL_H
00018 #define _TIMEVAL_H
00019 
00020 #ifndef WIN32_LEAN_AND_MEAN
00021 #define WIN32_LEAN_AND_MEAN
00022 #endif
00023 
00024 #include <winsock2.h>
00025 #include <time.h>
00026 
00027 #if defined(_MSC_VER) || defined(__BORLANDC__)
00028 #define EPOCHFILETIME (116444736000000000i64)
00029 #else
00030 #define EPOCHFILETIME (116444736000000000LL)
00031 #endif
00032 
00033 struct timezone {
00034     int tz_minuteswest; /* minutes W of Greenwich */
00035     int tz_dsttime;     /* type of dst correction */
00036 };
00037 
00038 
00039 #if !defined(_WIN32_WCE)
00040 
00041 __inline int gettimeofday(struct timeval *tv, struct timezone *tz)
00042 {
00043     FILETIME        ft;
00044     LARGE_INTEGER   li;
00045     __int64         t;
00046     static int      tzflag;
00047 
00048     if (tv)
00049     {
00050         GetSystemTimeAsFileTime(&ft);
00051         li.LowPart  = ft.dwLowDateTime;
00052         li.HighPart = ft.dwHighDateTime;
00053         t  = li.QuadPart;       /* In 100-nanosecond intervals */
00054         t -= EPOCHFILETIME;     /* Offset to the Epoch time */
00055         t /= 10;                /* In microseconds */
00056         tv->tv_sec  = (long)(t / 1000000);
00057         tv->tv_usec = (long)(t % 1000000);
00058     }
00059 
00060     if (tz)
00061     {
00062         if (!tzflag)
00063         {
00064             _tzset();
00065             tzflag++;
00066         }
00067         tz->tz_minuteswest = _timezone / 60;
00068         tz->tz_dsttime = _daylight;
00069     }
00070 
00071     return 0;
00072 }
00073 
00074 #else
00075 
00076 __inline int gettimeofday(struct timeval *tv, struct timezone *tz)
00077 {
00078         SYSTEMTIME      st;
00079     FILETIME        ft;
00080     LARGE_INTEGER   li;
00081     TIME_ZONE_INFORMATION tzi;
00082     __int64         t;
00083     static int      tzflag;
00084 
00085     if (tv)
00086     {
00087                 GetSystemTime(&st);
00088                 SystemTimeToFileTime(&st, &ft);
00089         li.LowPart  = ft.dwLowDateTime;
00090         li.HighPart = ft.dwHighDateTime;
00091         t  = li.QuadPart;       /* In 100-nanosecond intervals */
00092         t -= EPOCHFILETIME;     /* Offset to the Epoch time */
00093         t /= 10;                /* In microseconds */
00094         tv->tv_sec  = (long)(t / 1000000);
00095         tv->tv_usec = (long)(t % 1000000);
00096     }
00097 
00098     if (tz)
00099     {   
00100         GetTimeZoneInformation(&tzi);
00101                 
00102         tz->tz_minuteswest = tzi.Bias;
00103                 if (tzi.StandardDate.wMonth != 0)
00104         {
00105                         tz->tz_minuteswest += tzi.StandardBias * 60;
00106         }
00107 
00108         if (tzi.DaylightDate.wMonth != 0)
00109         {
00110             tz->tz_dsttime = 1;
00111         }
00112         else
00113         {
00114             tz->tz_dsttime = 0;
00115         }
00116     }
00117 
00118     return 0;
00119 }
00120 
00121 #endif /* _WIN32_WCE */
00122 
00123 #endif /* _TIMEVAL_H */

Generated on Thu Jun 11 06:17:02 2009 for GEOS by  doxygen 1.4.4