[libc] Implement clock_gettime in time
Summary
Implement the standard POSIX.1-2008 / POSIX.1-2024 function clock_gettime in <time.h>.
POSIX specification: https://pubs.opengroup.org/onlinepubs/9799919799/functions/clock_gettime.html
Background & Context
clock_gettime is standardized in POSIX.1-2008 / POSIX.1-2024:
int clock_gettime(clockid_t clock_id, struct timespec *tp);
clock_gettime is declared in libc/include/time.yaml but remains listed as unimplemented in libc/utils/docgen/time.yaml. While Linux, Darwin, and GPU implement entrypoints via internal helpers, Windows currently lacks the public entrypoint in libc/src/time/windows/ despite having the underlying implementation in libc/src/__support/time/windows/clock_gettime.cpp.
I would like to work on this issue.
@llvm/issue-subscribers-libc
Author: Aman Maurya (amanmaurya92)
POSIX specification: https://pubs.opengroup.org/onlinepubs/9799919799/functions/clock_gettime.html
Background & Context
clock_gettime is standardized in POSIX.1-2008 / POSIX.1-2024 to retrieve the time of the specified clock:
c int clock_gettime(clockid_t clock_id, struct timespec *tp);
In libc/include/time.yaml, clock_gettime is declared under POSIX standards, but it remains listed as unimplemented in libc/utils/docgen/time.yaml.
While Linux (libc/src/time/linux/clock_gettime.cpp), Darwin, and GPU currently provide entrypoint wrappers around internal helpers, target coverage remains incomplete. Specifically, Windows has the underlying implementation in libc/src/__support/time/windows/clock_gettime.cpp (using QueryPerformanceCounter and GetSystemTimePreciseAsFileTime), but lacks the first-class entrypoint in libc/src/time/windows/clock_gettime.cpp (unlike clock_getres which is already present).
To complete clock_gettime support:
- Add the entrypoint implementation in libc/src/time/<target>/clock_gettime.cpp and register it in CMakeLists.txt.
- Ensure hermetic unit tests in libc/test/src/time/clock_gettime_test.cpp pass across supported targets.
- Update libc/utils/docgen/time.yaml to reflect implementation status.
I would like to work on this issue.
i see the implementation status page saying clock_gettime is implemented?
Closing this issue as clock_gettime is already implemented and tested for Linux. Thanks @StarOne01 for pointing that out!"