[libcxx-commits] [libcxx] [libc++] Use clock_gettime in filesystem_clock on OpenBSD (PR #235292)
Brad Smith via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Oct 24 05:37:41 PDT 2026
https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/235292
OpenBSD does not define _POSIX_TIMERS > 0 because its POSIX timers
support is incomplete, but it does provide clock_gettime() and
CLOCK_MONOTONIC. chrono.cpp already special-cases OpenBSD for this;
filesystem_clock.cpp did not, so on OpenBSD it fell back to
gettimeofday() for file_time_type::clock::now().
Add __OpenBSD__ to the _LIBCPP_HAS_CLOCK_GETTIME check in
filesystem_clock.cpp so it matches chrono.cpp, and copy over the
comment explaining why.
>From d364864f94e98213268cc55a0304dcef6d153162 Mon Sep 17 00:00:00 2001
From: Brad Smith <brad at comstyle.com>
Date: Sat, 18 May 2024 22:05:10 -0400
Subject: [PATCH] [libc++] Use clock_gettime in filesystem_clock on OpenBSD
OpenBSD does not define _POSIX_TIMERS > 0 because its POSIX timers
support is incomplete, but it does provide clock_gettime() and
CLOCK_MONOTONIC. chrono.cpp already special-cases OpenBSD for this;
filesystem_clock.cpp did not, so on OpenBSD it fell back to
gettimeofday() for file_time_type::clock::now().
Add __OpenBSD__ to the _LIBCPP_HAS_CLOCK_GETTIME check in
filesystem_clock.cpp so it matches chrono.cpp, and copy over the
comment explaining why.
---
libcxx/src/filesystem/filesystem_clock.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/libcxx/src/filesystem/filesystem_clock.cpp b/libcxx/src/filesystem/filesystem_clock.cpp
index 0d360c51a7a37e..cb9af6a9b440be 100644
--- a/libcxx/src/filesystem/filesystem_clock.cpp
+++ b/libcxx/src/filesystem/filesystem_clock.cpp
@@ -36,8 +36,10 @@
# define _LIBCPP_HAS_TIMESPEC_GET
#endif
-#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__AMDGPU__) || defined(__NVPTX__) || \
- (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
+// OpenBSD and GPU do not have a fully conformant suite of POSIX timers, but
+// it does have clock_gettime and CLOCK_MONOTONIC which is all we need.
+#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__OpenBSD__) || defined(__AMDGPU__) || \
+ defined(__NVPTX__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0)
# define _LIBCPP_HAS_CLOCK_GETTIME
#endif
More information about the libcxx-commits
mailing list