stdlib: Add a Time module to the standard library

This commit is contained in:
Patrick Walton
2011-04-29 11:54:06 -07:00
parent c52fb52fbc
commit 5d3e553141
4 changed files with 43 additions and 0 deletions

View File

@@ -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++