[libc-commits] [libc] 4bb26aa - [libc] Implement clock_getres in time (#230826)

via libc-commits libc-commits at lists.llvm.org
Mon Oct 12 03:21:30 PDT 2026


Author: Aman Maurya
Date: 2026-10-12T15:51:24+05:30
New Revision: 4bb26aab4b7f2fb80f5c39e1e552c53aeacddae5

URL: https://github.com/llvm/llvm-project/commit/4bb26aab4b7f2fb80f5c39e1e552c53aeacddae5
DIFF: https://github.com/llvm/llvm-project/commit/4bb26aab4b7f2fb80f5c39e1e552c53aeacddae5.diff

LOG: [libc] Implement clock_getres in time (#230826)

Implement the standard POSIX.1-2008 / POSIX.1-2024 function
`clock_getres` in `<time.h>` on Linux and register it in the Linux
target entrypoints.

Fixes #230532

Added: 
    libc/src/time/linux/clock_getres.cpp

Modified: 
    libc/config/linux/aarch64/entrypoints.txt
    libc/config/linux/riscv/entrypoints.txt
    libc/config/linux/x86_64/entrypoints.txt
    libc/include/time.yaml
    libc/src/time/linux/CMakeLists.txt
    libc/test/src/time/CMakeLists.txt
    libc/test/src/time/clock_getres_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 046d94f429838..b76cc76c30bcd 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1425,6 +1425,7 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.time.ctime_r
     libc.src.time.clock
     libc.src.time.clock_getcpuclockid
+    libc.src.time.clock_getres
     libc.src.time.clock_gettime
     libc.src.time.clock_settime
     libc.src.time.
diff time

diff  --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 548a568e80b5b..0a0932bcb3e42 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1611,6 +1611,7 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.time.ctime_r
     libc.src.time.clock
     libc.src.time.clock_getcpuclockid
+    libc.src.time.clock_getres
     libc.src.time.clock_gettime
     libc.src.time.clock_settime
     libc.src.time.
diff time

diff  --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 600e0e29dbbb2..85bb01f416219 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1637,6 +1637,7 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.time.ctime_r
     libc.src.time.clock
     libc.src.time.clock_getcpuclockid
+    libc.src.time.clock_getres
     libc.src.time.clock_gettime
     libc.src.time.clock_settime
     libc.src.time.
diff time

diff  --git a/libc/include/time.yaml b/libc/include/time.yaml
index 44044604a6477..837b844579d27 100644
--- a/libc/include/time.yaml
+++ b/libc/include/time.yaml
@@ -77,6 +77,13 @@ functions:
     return_type: clock_t
     arguments:
       - type: void
+  - name: clock_getres
+    standards:
+      - posix
+    return_type: int
+    arguments:
+      - type: clockid_t
+      - type: struct timespec *
   - name: clock_gettime
     standards:
       - posix

diff  --git a/libc/src/time/linux/CMakeLists.txt b/libc/src/time/linux/CMakeLists.txt
index c16717a2acfaa..a868c06d73d33 100644
--- a/libc/src/time/linux/CMakeLists.txt
+++ b/libc/src/time/linux/CMakeLists.txt
@@ -47,6 +47,22 @@ add_entrypoint_object(
     libc.src.errno.errno
 )
 
+add_entrypoint_object(
+  clock_getres
+  SRCS
+    clock_getres.cpp
+  HDRS
+    ../clock_getres.h
+  DEPENDS
+    libc.hdr.types.clockid_t
+    libc.hdr.types.struct_timespec
+    libc.src.__support.OSUtil.linux.syscall_wrappers.clock_getres
+    libc.src.__support.common
+    libc.src.__support.libc_errno
+    libc.src.__support.macros.config
+    libc.src.errno.errno
+)
+
 add_entrypoint_object(
   clock_gettime
   SRCS

diff  --git a/libc/src/time/linux/clock_getres.cpp b/libc/src/time/linux/clock_getres.cpp
new file mode 100644
index 0000000000000..c3eb2e812d38c
--- /dev/null
+++ b/libc/src/time/linux/clock_getres.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Linux implementation of clock_getres function.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/time/clock_getres.h"
+
+#include "src/__support/OSUtil/linux/syscall_wrappers/clock_getres.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, clock_getres, (clockid_t clockid, timespec *tp)) {
+  auto result = linux_syscalls::clock_getres(clockid, tp);
+  if (!result) {
+    libc_errno = result.error();
+    return -1;
+  }
+  return 0;
+}
+
+} // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/test/src/time/CMakeLists.txt b/libc/test/src/time/CMakeLists.txt
index f04e0b1425e82..3f231c5fd793f 100644
--- a/libc/test/src/time/CMakeLists.txt
+++ b/libc/test/src/time/CMakeLists.txt
@@ -142,6 +142,8 @@ add_libc_test(
   SRCS
     clock_getres_test.cpp
   DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.time_macros
     libc.src.time.clock_getres
 )
 

diff  --git a/libc/test/src/time/clock_getres_test.cpp b/libc/test/src/time/clock_getres_test.cpp
index d8b3f01b37a38..3817b282429d7 100644
--- a/libc/test/src/time/clock_getres_test.cpp
+++ b/libc/test/src/time/clock_getres_test.cpp
@@ -1,11 +1,17 @@
-//===-- Unittests for clock_getres- ---------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Unittests for clock_getres.
+///
+//===----------------------------------------------------------------------===//
 
+#include "hdr/errno_macros.h"
 #include "hdr/time_macros.h"
 #include "src/time/clock_getres.h"
 #include "test/UnitTest/ErrnoSetterMatcher.h"


        


More information about the libc-commits mailing list