diff --git a/src/time/src/constants.rs b/src/time/src/constants.rs index 1836c7cec94abbd0930f64574a4d258f41fa08e4..fe6eae8e3d58b9e9e724c6cb1c36c2054cda7a2c 100644 --- a/src/time/src/constants.rs +++ b/src/time/src/constants.rs @@ -47,3 +47,5 @@ pub(crate) const CLOCK_REALTIME: clockid_t = 0; pub(crate) const CLOCK_MONOTONIC: clockid_t = 1; pub(crate) const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2; pub(crate) const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3; + +pub(crate) const CLOCKS_PER_SEC: time_t = 1_000_000; \ No newline at end of file diff --git a/src/time/src/lib.rs b/src/time/src/lib.rs index 58d862ff376ce4264731e05b958e77e822ae9ea4..e93f4c752ab19ae7b58f6123cc5a7fe7a135faed 100644 --- a/src/time/src/lib.rs +++ b/src/time/src/lib.rs @@ -104,13 +104,13 @@ pub extern "C" fn clock() -> clock_t { return -1; } - if ts.tv_sec > time_t::max_value() / 1_000_000 - || ts.tv_nsec / 1000 > time_t::max_value() - 1_000_000 * ts.tv_sec + if ts.tv_sec > time_t::max_value() / CLOCKS_PER_SEC + || ts.tv_nsec / 1000 > time_t::max_value() - CLOCKS_PER_SEC * ts.tv_sec { return -1; } - return ts.tv_sec * 1_000_000 + ts.tv_nsec / 1000; + return ts.tv_sec * CLOCKS_PER_SEC + ts.tv_nsec / 1000; } #[no_mangle]