From dcfcc6454b20331ed7810ee2b9ff0b7429a82fd0 Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Wed, 23 Nov 2022 21:44:27 -0500 Subject: [PATCH] lib: posix: sleep() should report unslept time in seconds In the case that `sleep()` is interrupted, the POSIX spec requires it to return the number of "unslept" seconds (i.e. the number of seconds requested minus the number of seconds actually slept). Since `k_sleep()` already returns the amount of "unslept" time in ms, we can simply use that. Signed-off-by: Chris Friedt --- lib/posix/sleep.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/posix/sleep.c b/lib/posix/sleep.c index bf305d477fa..377817b769a 100644 --- a/lib/posix/sleep.c +++ b/lib/posix/sleep.c @@ -14,8 +14,12 @@ */ unsigned sleep(unsigned int seconds) { - k_sleep(K_SECONDS(seconds)); - return 0; + int rem; + + rem = k_sleep(K_SECONDS(seconds)); + __ASSERT_NO_MSG(rem >= 0); + + return rem / MSEC_PER_SEC; } /** * @brief Suspend execution for microsecond intervals.