• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List

timeval.h

00001 /**********************************************************************
00002  * $Id: timeval.h 2787 2009-12-03 19:59:06Z mloskot $
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 #ifndef GEOS_TIMEVAL_H
00017 #define GEOS_TIMEVAL_H
00018 
00019 #ifndef WIN32_LEAN_AND_MEAN
00020 #define WIN32_LEAN_AND_MEAN
00021 #endif
00022 
00023 #include <winsock2.h>
00024 #include <time.h>
00025 
00026 #if defined(_MSC_VER) || defined(__BORLANDC__)
00027 #define EPOCHFILETIME (116444736000000000i64)
00028 #else
00029 #define EPOCHFILETIME (116444736000000000LL)
00030 #endif
00031 
00032 struct timezone {
00033     int tz_minuteswest; /* minutes W of Greenwich */
00034     int tz_dsttime;     /* type of dst correction */
00035 };
00036 
00037 
00038 #if !defined(_WIN32_WCE)
00039 
00040 __inline int gettimeofday(struct timeval *tv, struct timezone *tz)
00041 {
00042     FILETIME        ft;
00043     LARGE_INTEGER   li;
00044     __int64         t;
00045     static int      tzflag;
00046 
00047     if (tv)
00048     {
00049         GetSystemTimeAsFileTime(&ft);
00050         li.LowPart  = ft.dwLowDateTime;
00051         li.HighPart = ft.dwHighDateTime;
00052         t  = li.QuadPart;       /* In 100-nanosecond intervals */
00053         t -= EPOCHFILETIME;     /* Offset to the Epoch time */
00054         t /= 10;                /* In microseconds */
00055         tv->tv_sec  = (long)(t / 1000000);
00056         tv->tv_usec = (long)(t % 1000000);
00057     }
00058 
00059     if (tz)
00060     {
00061         if (!tzflag)
00062         {
00063             _tzset();
00064             tzflag++;
00065         }
00066         tz->tz_minuteswest = _timezone / 60;
00067         tz->tz_dsttime = _daylight;
00068     }
00069 
00070     return 0;
00071 }
00072 
00073 #else
00074 
00075 __inline int gettimeofday(struct timeval *tv, struct timezone *tz)
00076 {
00077         SYSTEMTIME      st;
00078     FILETIME        ft;
00079     LARGE_INTEGER   li;
00080     TIME_ZONE_INFORMATION tzi;
00081     __int64         t;
00082     static int      tzflag;
00083 
00084     if (tv)
00085     {
00086                 GetSystemTime(&st);
00087                 SystemTimeToFileTime(&st, &ft);
00088         li.LowPart  = ft.dwLowDateTime;
00089         li.HighPart = ft.dwHighDateTime;
00090         t  = li.QuadPart;       /* In 100-nanosecond intervals */
00091         t -= EPOCHFILETIME;     /* Offset to the Epoch time */
00092         t /= 10;                /* In microseconds */
00093         tv->tv_sec  = (long)(t / 1000000);
00094         tv->tv_usec = (long)(t % 1000000);
00095     }
00096 
00097     if (tz)
00098     {   
00099         GetTimeZoneInformation(&tzi);
00100                 
00101         tz->tz_minuteswest = tzi.Bias;
00102                 if (tzi.StandardDate.wMonth != 0)
00103         {
00104                         tz->tz_minuteswest += tzi.StandardBias * 60;
00105         }
00106 
00107         if (tzi.DaylightDate.wMonth != 0)
00108         {
00109             tz->tz_dsttime = 1;
00110         }
00111         else
00112         {
00113             tz->tz_dsttime = 0;
00114         }
00115     }
00116 
00117     return 0;
00118 }
00119 
00120 #endif /* _WIN32_WCE */
00121 
00122 #endif /* GEOS_TIMEVAL_H */

Generated on Thu Jul 22 2010 for GEOS by  doxygen 1.7.1