00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "timeval.h"
00025
00026 #ifndef HAVE_GETTIMEOFDAY
00027
00028 #ifdef WIN32
00029 #include <mmsystem.h>
00030
00031 static int gettimeofday(struct timeval *tp, void *nothing)
00032 {
00033 #ifdef WITHOUT_MM_LIB
00034 SYSTEMTIME st;
00035 time_t tt;
00036 struct tm tmtm;
00037
00038 GetLocalTime (&st);
00039 tmtm.tm_sec = st.wSecond;
00040 tmtm.tm_min = st.wMinute;
00041 tmtm.tm_hour = st.wHour;
00042 tmtm.tm_mday = st.wDay;
00043 tmtm.tm_mon = st.wMonth - 1;
00044 tmtm.tm_year = st.wYear - 1900;
00045 tmtm.tm_isdst = -1;
00046 tt = mktime (&tmtm);
00047 tp->tv_sec = tt;
00048 tp->tv_usec = st.wMilliseconds * 1000;
00049 #else
00050
00056 unsigned long Ticks = 0;
00057 unsigned long Sec =0;
00058 unsigned long Usec = 0;
00059 Ticks = timeGetTime();
00060
00061 Sec = Ticks/1000;
00062 Usec = (Ticks - (Sec*1000))*1000;
00063 tp->tv_sec = Sec;
00064 tp->tv_usec = Usec;
00065 #endif
00066 (void)nothing;
00067 return 0;
00068 }
00069 #else
00070
00071 static int gettimeofday(struct timeval *tp, void *nothing)
00072 {
00073 (void)nothing;
00074 tp->tv_sec = (long)time(NULL);
00075 tp->tv_usec = 0;
00076 return 0;
00077 }
00078 #endif
00079 #endif
00080
00081
00082 struct timeval curlx_tvnow(void)
00083 {
00084 struct timeval now;
00085 (void)gettimeofday(&now, NULL);
00086 return now;
00087 }
00088
00089
00090
00091
00092
00093
00094
00095 long curlx_tvdiff(struct timeval newer, struct timeval older)
00096 {
00097 return (newer.tv_sec-older.tv_sec)*1000+
00098 (newer.tv_usec-older.tv_usec)/1000;
00099 }
00100
00101
00102
00103
00104
00105
00106 double curlx_tvdiff_secs(struct timeval newer, struct timeval older)
00107 {
00108 return (double)(newer.tv_sec-older.tv_sec)+
00109 (double)(newer.tv_usec-older.tv_usec)/1000000.0;
00110 }
00111
00112
00113 long Curl_tvlong(struct timeval t1)
00114 {
00115 return t1.tv_sec;
00116 }