Introduce clock_nanosleep()

This commit is contained in:
Justine Tunney 2022-10-05 06:37:15 -07:00
parent fe3216e961
commit b75a4654cf
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
33 changed files with 553 additions and 100 deletions

View file

@ -18,6 +18,13 @@
*/
#include "libc/calls/struct/timeval.h"
/**
* Reduces `ts` from 1e-9 to 1e-6 granularity w/ ceil rounding.
*/
struct timeval _timespec_totimeval(struct timespec ts) {
return (struct timeval){ts.tv_sec, ts.tv_nsec / 1000};
if (ts.tv_nsec < 1000000000 - 999) {
return (struct timeval){ts.tv_sec, (ts.tv_nsec + 999) / 1000};
} else {
return (struct timeval){ts.tv_sec + 1, 0};
}
}