LibC: Implement `clock` in terms of `clock_gettime`

This allows clock to "just work" after I update clock_gettime to support
CLOCK_PROCESS_CPUTIME_ID.
This commit is contained in:
Bananymous 2025-01-24 19:58:44 +02:00
parent 2a16a67aed
commit 60bffb5f49
1 changed files with 5 additions and 2 deletions

View File

@ -20,8 +20,11 @@ int nanosleep(const struct timespec* rqtp, struct timespec* rmtp)
clock_t clock(void) clock_t clock(void)
{ {
dwarnln("TODO: clock"); timespec ts;
return -1; if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) == -1)
return -1;
return ((uint64_t)ts.tv_sec * CLOCKS_PER_SEC)
+ ((uint64_t)ts.tv_nsec * CLOCKS_PER_SEC / 1'000'000'000);
} }
time_t time(time_t* tloc) time_t time(time_t* tloc)