diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-29 13:17:30 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-29 13:17:30 +0000 |
| commit | fc6ff10acb9d00ea1c8c5924869e0efbd38093c5 (patch) | |
| tree | a4cb5d9d9d0ea2702de42df1e3c2fbe40185e293 /std/time.zc | |
| parent | da9e8758e9d89dc7362be67f8e7573309efe170c (diff) | |
Objective-C interop + a few improvements
Diffstat (limited to 'std/time.zc')
| -rw-r--r-- | std/time.zc | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/std/time.zc b/std/time.zc index 1191821..8e7cc6c 100644 --- a/std/time.zc +++ b/std/time.zc @@ -1,18 +1,28 @@ - import "./core.zc" +include <time.h> +include <unistd.h> +include <sys/time.h> +include <stdlib.h> + raw { - #include <time.h> - #include <unistd.h> - #include <sys/time.h> - static uint64_t _time_now_impl(void) { struct timeval tv; gettimeofday(&tv, NULL); return (uint64_t)(tv.tv_sec) * 1000 + (uint64_t)(tv.tv_usec) / 1000; } + + static long _z_time_time(void) { + return (long)time(NULL); + } } +extern fn srand(seed: U32); +extern fn rand() -> int; +extern fn usleep(micros: U32) -> int; +extern fn _time_now_impl() -> U64; +extern fn _z_time_time() -> long; + struct Duration { millis: U64; } @@ -33,10 +43,8 @@ extern size_t __zen_hash_seed; impl Time { fn randomize_hash() { - raw { - srand(time(NULL)); - __zen_hash_seed ^= (size_t)rand(); - } + srand((U32)_z_time_time()); + __zen_hash_seed ^= (size_t)rand(); } fn now() -> U64 { |
