summaryrefslogtreecommitdiff
path: root/lib/timeval.h
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2017-10-23 12:05:49 +0200
committerDaniel Stenberg <daniel@haxx.se>2017-10-25 09:54:37 +0200
commitb9d25f9a6b3ca791385b80a6a3c3fa5ae113e1e0 (patch)
treead56d8b7a703e96e9de0ef07bacab079b7169904 /lib/timeval.h
parent016c6a6abb525ffb9431a00a4eda6b70683f838e (diff)
downloadcurl-b9d25f9a6b3ca791385b80a6a3c3fa5ae113e1e0.tar.gz
timediff: return timediff_t from the time diff functions
... to cater for systems with unsigned time_t variables. - Renamed the functions to curlx_timediff and Curl_timediff_us. - Added overflow protection for both of them in either direction for both 32 bit and 64 bit time_ts - Reprefixed the curlx_time functions to use Curl_* Reported-by: Peter Piekarski Fixes #2004 Closes #2005
Diffstat (limited to 'lib/timeval.h')
-rw-r--r--lib/timeval.h27
1 files changed, 12 insertions, 15 deletions
diff --git a/lib/timeval.h b/lib/timeval.h
index 1ee4b3044..b2f0e0d97 100644
--- a/lib/timeval.h
+++ b/lib/timeval.h
@@ -22,19 +22,21 @@
*
***************************************************************************/
-/*
- * CAUTION: this header is designed to work when included by the app-side
- * as well as the library. Do not mix with library internals!
- */
-
#include "curl_setup.h"
+#if SIZEOF_TIME_T < 8
+typedef int timediff_t;
+#else
+typedef ssize_t timediff_t;
+#endif
+
+
struct curltime {
- time_t tv_sec; /* seconds */
- unsigned int tv_usec; /* microseconds */
+ time_t tv_sec; /* seconds */
+ int tv_usec; /* microseconds */
};
-struct curltime curlx_tvnow(void);
+struct curltime Curl_tvnow(void);
/*
* Make sure that the first argument (t1) is the more recent time and t2 is
@@ -42,7 +44,7 @@ struct curltime curlx_tvnow(void);
*
* Returns: the time difference in number of milliseconds.
*/
-time_t curlx_tvdiff(struct curltime t1, struct curltime t2);
+timediff_t Curl_timediff(struct curltime t1, struct curltime t2);
/*
* Make sure that the first argument (t1) is the more recent time and t2 is
@@ -50,12 +52,7 @@ time_t curlx_tvdiff(struct curltime t1, struct curltime t2);
*
* Returns: the time difference in number of microseconds.
*/
-time_t Curl_tvdiff_us(struct curltime newer, struct curltime older);
-
-/* These two defines below exist to provide the older API for library
- internals only. */
-#define Curl_tvnow() curlx_tvnow()
-#define Curl_tvdiff(x,y) curlx_tvdiff(x,y)
+timediff_t Curl_timediff_us(struct curltime newer, struct curltime older);
#endif /* HEADER_CURL_TIMEVAL_H */