1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 * $Id: timeval.c,v 1.2 2007-03-15 19:22:13 andy Exp $
22 ***************************************************************************/
26 #ifndef HAVE_GETTIMEOFDAY
31 static int gettimeofday(struct timeval
*tp
, void *nothing
)
37 /* mktime converts local to UTC */
39 tmtm
.tm_sec
= st
.wSecond
;
40 tmtm
.tm_min
= st
.wMinute
;
41 tmtm
.tm_hour
= st
.wHour
;
42 tmtm
.tm_mday
= st
.wDay
;
43 tmtm
.tm_mon
= st
.wMonth
- 1;
44 tmtm
.tm_year
= st
.wYear
- 1900;
48 tp
->tv_usec
= st
.wMilliseconds
* 1000;
51 ** The earlier time calculations using GetLocalTime
52 ** had a time resolution of 10ms.The timeGetTime, part
53 ** of multimedia apis offer a better time resolution
54 ** of 1ms.Need to link against winmm.lib for this
56 unsigned long Ticks
= 0;
58 unsigned long Usec
= 0;
59 Ticks
= timeGetTime();
62 Usec
= (Ticks
- (Sec
*1000))*1000;
65 #endif /* WITHOUT_MM_LIB */
70 /* non-win32 version of Curl_gettimeofday() */
71 static int gettimeofday(struct timeval
*tp
, void *nothing
)
73 (void)nothing
; /* we don't support specific time-zones */
74 tp
->tv_sec
= (long)time(NULL
);
79 #endif /* HAVE_GETTIMEOFDAY */
81 /* Return the current time in a timeval struct */
82 struct timeval
curlx_tvnow(void)
85 (void)gettimeofday(&now
, NULL
);
90 * Make sure that the first argument is the more recent time, as otherwise
91 * we'll get a weird negative time-diff back...
93 * Returns: the time difference in number of milliseconds.
95 long curlx_tvdiff(struct timeval newer
, struct timeval older
)
97 return (newer
.tv_sec
-older
.tv_sec
)*1000+
98 (newer
.tv_usec
-older
.tv_usec
)/1000;
102 * Same as curlx_tvdiff but with full usec resolution.
104 * Returns: the time difference in seconds with subsecond resolution.
106 double curlx_tvdiff_secs(struct timeval newer
, struct timeval older
)
108 return (double)(newer
.tv_sec
-older
.tv_sec
)+
109 (double)(newer
.tv_usec
-older
.tv_usec
)/1000000.0;
112 /* return the number of seconds in the given input timeval struct */
113 long Curl_tvlong(struct timeval t1
)