From e88a19467e85116a81e5fff6475610da6cc1acb3 Mon Sep 17 00:00:00 2001 From: goldengrandpa <74250839+guoguozi123456@users.noreply.github.com> Date: Thu, 1 Jun 2023 10:52:33 +0800 Subject: [PATCH] =?UTF-8?q?[ctime]=E8=A7=A3=E5=86=B3clock=5Fgettime?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=87=BA=E6=9D=A5=E7=9A=84nsec=E8=B6=85?= =?UTF-8?q?=E8=BF=871sec=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/ctime.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/libc/compilers/common/ctime.c b/components/libc/compilers/common/ctime.c index b6d613564b..d5aff8618b 100644 --- a/components/libc/compilers/common/ctime.c +++ b/components/libc/compilers/common/ctime.c @@ -677,8 +677,13 @@ int clock_gettime(clockid_t clockid, struct timespec *tp) level = rt_hw_interrupt_disable(); tick = rt_tick_get(); /* get tick */ tp->tv_sec = _timevalue.tv_sec + tick / RT_TICK_PER_SECOND; - tp->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000; + tp->tv_nsec = (_timevalue.tv_usec + (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK) * 1000U; rt_hw_interrupt_enable(level); + if (tp->tv_nsec > 1000000000ULL) + { + tp->tv_nsec %= 1000000000ULL; + tp->tv_sec += 1; + } } break; #endif