summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/l_crawl.cc
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2013-05-15 16:12:38 +0200
committerAdam Borowski <kilobyte@angband.pl>2013-05-15 16:12:38 +0200
commit9e32ab9491552aafef2240bc60197fb763cb0842 (patch)
tree74e61f9146ff9a3c99f0cad6a1d1307ca9cdb14f /crawl-ref/source/l_crawl.cc
parentc309f551d72e390eda6ad2e7c4782cbe261ab47b (diff)
downloadcrawl-ref-9e32ab9491552aafef2240bc60197fb763cb0842.tar.gz
crawl-ref-9e32ab9491552aafef2240bc60197fb763cb0842.zip
Avoid use of gettimeofday() on Windows (not implemented on MSVC).
Also, drop handling of an impossible error. A local variable on the stack is quite likely to be within the process' address space. And even for some reason (?!?) it'd be not, the very next line will give us a nice SIGSEGV anyway :)
Diffstat (limited to 'crawl-ref/source/l_crawl.cc')
-rw-r--r--crawl-ref/source/l_crawl.cc28
1 files changed, 19 insertions, 9 deletions
diff --git a/crawl-ref/source/l_crawl.cc b/crawl-ref/source/l_crawl.cc
index 4e35801587..56149d2c65 100644
--- a/crawl-ref/source/l_crawl.cc
+++ b/crawl-ref/source/l_crawl.cc
@@ -43,8 +43,12 @@ module "crawl"
#include "view.h"
#include "worley.h"
-#include <sys/time.h>
-#include <time.h>
+#ifdef TARGET_OS_WINDOWS
+# include "windows.h"
+#else
+# include <sys/time.h>
+# include <time.h>
+#endif
/////////////////////////////////////////////////////////////////////
// User accessible
@@ -1112,15 +1116,21 @@ LUAFN(_crawl_redraw_stats)
LUAFN(_crawl_millis)
{
+#ifdef TARGET_OS_WINDOWS
+ // MSVC has no gettimeofday().
+ FILETIME ft;
+ GetSystemTimeAsFileTime(&ft);
+ uint64_t tt = ft.dwHighDateTime;
+ tt <<= 32;
+ tt |= ft.dwLowDateTime;
+ tt /= 10000;
+ tt -= 11644473600000ULL;
+ lua_pushnumber(ls, tt);
+#else
struct timeval tv;
- const int error = gettimeofday(&tv, nullptr);
- if (error)
- {
- luaL_error(ls, make_stringf("Failed to get time: %s",
- strerror(error)).c_str());
- }
-
+ gettimeofday(&tv, nullptr);
lua_pushnumber(ls, tv.tv_sec * 1000 + tv.tv_usec / 1000);
+#endif
return 1;
}