Skip to content

Commit fbea9e7

Browse files
Chris Friedtcfriedt
authored andcommitted
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 <[email protected]> (cherry picked from commit dcfcc64)
1 parent 4d92982 commit fbea9e7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/posix/sleep.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
*/
1515
unsigned sleep(unsigned int seconds)
1616
{
17-
k_sleep(K_SECONDS(seconds));
18-
return 0;
17+
int rem;
18+
19+
rem = k_sleep(K_SECONDS(seconds));
20+
__ASSERT_NO_MSG(rem >= 0);
21+
22+
return rem / MSEC_PER_SEC;
1923
}
2024
/**
2125
* @brief Suspend execution for microsecond intervals.

0 commit comments

Comments
 (0)