summaryrefslogtreecommitdiff
path: root/components/libc
diff options
context:
space:
mode:
authorgoldengrandpa <[email protected]>2023-06-01 10:52:33 +0800
committerGitHub <[email protected]>2023-05-31 22:52:33 -0400
commite88a19467e85116a81e5fff6475610da6cc1acb3 (patch)
treedc23ab78728dbea78323168a4bd50507d91e84d3 /components/libc
parent16382412973c469d87132ef7b661d86b6766e59f (diff)
[ctime]解决clock_gettime计算出来的nsec超过1sec的问题
Diffstat (limited to 'components/libc')
-rw-r--r--components/libc/compilers/common/ctime.c7
1 files changed, 6 insertions, 1 deletions
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