123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- #include "timeval.h"
- #if defined(WIN32) && !defined(MSDOS)
- struct timeval curlx_tvnow(void)
- {
-
- struct timeval now;
- DWORD milliseconds = GetTickCount();
- now.tv_sec = milliseconds / 1000;
- now.tv_usec = (milliseconds % 1000) * 1000;
- return now;
- }
- #elif defined(HAVE_CLOCK_GETTIME_MONOTONIC)
- struct timeval curlx_tvnow(void)
- {
-
- struct timeval now;
- struct timespec tsnow;
- if(0 == clock_gettime(CLOCK_MONOTONIC, &tsnow)) {
- now.tv_sec = tsnow.tv_sec;
- now.tv_usec = tsnow.tv_nsec / 1000;
- }
-
- #ifdef HAVE_GETTIMEOFDAY
- else
- (void)gettimeofday(&now, NULL);
- #else
- else {
- now.tv_sec = (long)time(NULL);
- now.tv_usec = 0;
- }
- #endif
- return now;
- }
- #elif defined(HAVE_GETTIMEOFDAY)
- struct timeval curlx_tvnow(void)
- {
-
- struct timeval now;
- (void)gettimeofday(&now, NULL);
- return now;
- }
- #else
- struct timeval curlx_tvnow(void)
- {
-
- struct timeval now;
- now.tv_sec = (long)time(NULL);
- now.tv_usec = 0;
- return now;
- }
- #endif
- long curlx_tvdiff(struct timeval newer, struct timeval older)
- {
- return (newer.tv_sec-older.tv_sec)*1000+
- (newer.tv_usec-older.tv_usec)/1000;
- }
- double curlx_tvdiff_secs(struct timeval newer, struct timeval older)
- {
- if(newer.tv_sec != older.tv_sec)
- return (double)(newer.tv_sec-older.tv_sec)+
- (double)(newer.tv_usec-older.tv_usec)/1000000.0;
- else
- return (double)(newer.tv_usec-older.tv_usec)/1000000.0;
- }
- long Curl_tvlong(struct timeval t1)
- {
- return t1.tv_sec;
- }
|