diff options
| author | Patrick Walton <[email protected]> | 2011-04-29 11:54:06 -0700 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2011-04-29 11:54:06 -0700 |
| commit | 5d3e5531412952c556fabb541536bcae34b0ce09 (patch) | |
| tree | fabf066bf9227a0026be2e2b62f2012e9d32ee14 /src/rt | |
| parent | rustc: Remove the wrong-compiler warning; we're self-hosting now. (diff) | |
| download | rust-5d3e5531412952c556fabb541536bcae34b0ce09.tar.xz rust-5d3e5531412952c556fabb541536bcae34b0ce09.zip | |
stdlib: Add a Time module to the standard library
Diffstat (limited to 'src/rt')
| -rw-r--r-- | src/rt/rust_builtin.cpp | 29 | ||||
| -rw-r--r-- | src/rt/rustrt.def.in | 1 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index a2323898..297b9df7 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -1,6 +1,10 @@ #include "rust_internal.h" +#if !defined(__WIN32__) +#include <sys/time.h> +#endif + /* Native builtins. */ extern "C" CDECL rust_str* @@ -508,6 +512,31 @@ rust_ptr_eq(rust_task *task, type_desc *t, rust_box *a, rust_box *b) { return a == b; } +#if defined(__WIN32__) +extern "C" CDECL void +get_time(rust_task *task, uint32_t *sec, uint32_t *usec) { + SYSTEMTIME systemTime; + FILETIME fileTime; + GetSystemTime(&systemTime); + if (!SystemTimeToFileTime(&systemTime, &fileTime)) { + task->fail(1); + return; + } + + // FIXME: This is probably completely wrong. + *sec = fileTime.dwHighDateTime; + *usec = fileTime.dwLowDateTime; +} +#else +extern "C" CDECL void +get_time(rust_task *task, uint32_t *sec, uint32_t *usec) { + struct timeval tv; + gettimeofday(&tv, NULL); + *sec = tv.tv_sec; + *usec = tv.tv_usec; +} +#endif + // // Local Variables: // mode: C++ diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index d30c146e..b2d42463 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -8,6 +8,7 @@ debug_tag debug_trap debug_tydesc do_gc +get_time last_os_error rand_free rand_new |