diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-03-27 17:19:03 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-03-27 17:19:03 (GMT) |
commit | 34dc0f46ae5c0c9ec91d9402fac61111b802855f (patch) | |
tree | 274e9bac8b7049fabac4f16161676edfd847c771 /Python/pytime.c | |
parent | 7181dec3f12f11c9a5f4adc6336b1c7273452308 (diff) | |
download | cpython-34dc0f46ae5c0c9ec91d9402fac61111b802855f.zip cpython-34dc0f46ae5c0c9ec91d9402fac61111b802855f.tar.gz cpython-34dc0f46ae5c0c9ec91d9402fac61111b802855f.tar.bz2 |
Issue #22117: The signal modules uses the new _PyTime_t API
* Add _PyTime_AsTimespec()
* Add unit tests for _PyTime_AsTimespec()
Diffstat (limited to 'Python/pytime.c')
-rw-r--r-- | Python/pytime.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Python/pytime.c b/Python/pytime.c index 0f30f42..bd94787 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -572,6 +572,27 @@ _PyTime_AsTimeval(_PyTime_t t, struct timeval *tv, _PyTime_round_t round) return 0; } +#ifdef HAVE_CLOCK_GETTIME +int +_PyTime_AsTimespec(_PyTime_t t, struct timespec *ts) +{ + _PyTime_t sec, nsec; + sec = t / SEC_TO_NS; + nsec = t % SEC_TO_NS; + if (nsec < 0) { + nsec += SEC_TO_NS; + sec -= 1; + } + ts->tv_sec = (time_t)sec; + if ((_PyTime_t)ts->tv_sec != sec) { + _PyTime_overflow(); + return -1; + } + ts->tv_nsec = nsec; + return 0; +} +#endif + static int pygettimeofday_new(_PyTime_t *tp, _Py_clock_info_t *info, int raise) { |