aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-08-04 20:42:02 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-08-04 20:42:02 +0000
commite27fa00e1c07739945dd4369d9df0e2415ecb9ad (patch)
tree8bf5b76f6b9d91cb0431f3053ad08c69ede2819e
parent0e77ad987f64ec0044af0b3dd1d30f289c9c3419 (diff)
downloadluasocket-e27fa00e1c07739945dd4369d9df0e2415ecb9ad.tar.gz
luasocket-e27fa00e1c07739945dd4369d9df0e2415ecb9ad.tar.bz2
luasocket-e27fa00e1c07739945dd4369d9df0e2415ecb9ad.zip
Gettime returns time in the Unix Epoch time both on windows and unix.
-rw-r--r--src/timeout.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/timeout.c b/src/timeout.c
index 66b98dd..152af29 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -118,20 +118,25 @@ p_tm tm_markstart(p_tm tm) {
118} 118}
119 119
120/*-------------------------------------------------------------------------*\ 120/*-------------------------------------------------------------------------*\
121* Gets time in ms, relative to system startup. 121* Gets time in s, relative to January 1, 1970 (UTC)
122* Returns 122* Returns
123* time in ms. 123* time in s.
124\*-------------------------------------------------------------------------*/ 124\*-------------------------------------------------------------------------*/
125#ifdef _WIN32 125#ifdef _WIN32
126double tm_gettime(void) { 126double tm_gettime(void) {
127 FILETIME ft; 127 FILETIME ft;
128 double t;
128 GetSystemTimeAsFileTime(&ft); 129 GetSystemTimeAsFileTime(&ft);
129 return ft.dwLowDateTime/1.0e7 + ft.dwHighDateTime*(4294967296.0/1.0e7); 130 /* Windows file time (time since January 1, 1601 (UTC)) */
131 t = ft.dwLowDateTime/1.0e7 + ft.dwHighDateTime*(4294967296.0/1.0e7);
132 /* convert to Unix Epoch time (time since January 1, 1970 (UTC)) */
133 return (t - 11644473600.0);
130} 134}
131#else 135#else
132double tm_gettime(void) { 136double tm_gettime(void) {
133 struct timeval v; 137 struct timeval v;
134 gettimeofday(&v, (struct timezone *) NULL); 138 gettimeofday(&v, (struct timezone *) NULL);
139 /* Unix Epoch time (time since January 1, 1970 (UTC)) */
135 return v.tv_sec + v.tv_usec/1.0e6; 140 return v.tv_sec + v.tv_usec/1.0e6;
136} 141}
137#endif 142#endif