Main Page | Namespace List | Class Hierarchy | Data Structures | File List | Data Fields | Globals

timeval.h

Go to the documentation of this file.
00001 /*
00002  * timeval.h    1.0 01/12/19
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 <windows.h>
00017 #include <time.h>
00018 
00019 #ifndef __GNUC__
00020 #define EPOCHFILETIME (116444736000000000i64)
00021 #else
00022 #define EPOCHFILETIME (116444736000000000LL)
00023 #endif
00024 
00025 struct timeval {
00026     long tv_sec;        /* seconds */
00027     long tv_usec;  /* microseconds */
00028 };
00029 
00030 struct timezone {
00031     int tz_minuteswest; /* minutes W of Greenwich */
00032     int tz_dsttime;     /* type of dst correction */
00033 };
00034 
00035 __inline int gettimeofday(struct timeval *tv, struct timezone *tz)
00036 {
00037     FILETIME        ft;
00038     LARGE_INTEGER   li;
00039     __int64         t;
00040     static int      tzflag;
00041 
00042     if (tv)
00043     {
00044         GetSystemTimeAsFileTime(&ft);
00045         li.LowPart  = ft.dwLowDateTime;
00046         li.HighPart = ft.dwHighDateTime;
00047         t  = li.QuadPart;       /* In 100-nanosecond intervals */
00048         t -= EPOCHFILETIME;     /* Offset to the Epoch time */
00049         t /= 10;                /* In microseconds */
00050         tv->tv_sec  = (long)(t / 1000000);
00051         tv->tv_usec = (long)(t % 1000000);
00052     }
00053 
00054     if (tz)
00055     {
00056         if (!tzflag)
00057         {
00058             _tzset();
00059             tzflag++;
00060         }
00061         tz->tz_minuteswest = _timezone / 60;
00062         tz->tz_dsttime = _daylight;
00063     }
00064 
00065     return 0;
00066 }
00067 
00068 #else  /* _WIN32 */
00069 
00070 #include <sys/time.h>
00071 
00072 #endif /* _WIN32 */
00073 
00074 #endif /* _TIMEVAL_H */

Generated on Wed Jun 23 18:47:21 2004 for cZUI by doxygen 1.3.5