[libcxx-commits] [libcxx] [libcxx] Fix compiling for macOS versions before 10.13 (PR #126669)

Benjamin Schaaf via libcxx-commits libcxx-commits at lists.llvm.org
Mon Feb 10 21:35:17 PST 2025


https://github.com/BenjaminSchaaf created https://github.com/llvm/llvm-project/pull/126669

utimensat was introduced in macOS 10.13. UTIME_OMIT is still defined even when targeting 10.9 from newer versions of macOS, so this can't be used as a signal for utimensat availability.

>From a032746c5c3779193dc912e4a4e7213609e80bbe Mon Sep 17 00:00:00 2001
From: Benjamin Schaaf <bschaaf at sublimetext.com>
Date: Tue, 11 Feb 2025 16:34:53 +1100
Subject: [PATCH] [libcxx] Fix compiling for macOS versions before 10.13

utimensat was introduced in macOS 10.13. UTIME_OMIT is still defined
even when targeting 10.9 from newer versions of macOS, so this can't be
used as a signal for utimensat availability.
---
 libcxx/src/filesystem/time_utils.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libcxx/src/filesystem/time_utils.h b/libcxx/src/filesystem/time_utils.h
index 89352e5bd6abbbb..e82738eb7036372 100644
--- a/libcxx/src/filesystem/time_utils.h
+++ b/libcxx/src/filesystem/time_utils.h
@@ -32,8 +32,14 @@
 #  include <sys/time.h> // for ::utimes as used in __last_write_time
 #endif
 
+// MacOS version 10.13 introduces utimensat
+#if defined(__APPLE__)
+#  if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) &&                                                       \
+       __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101300)
+#    define _LIBCPP_USE_UTIMENSAT
+#  endif
 // We can use the presence of UTIME_OMIT to detect platforms that provide utimensat.
-#if defined(UTIME_OMIT)
+#elif defined(UTIME_OMIT)
 #  define _LIBCPP_USE_UTIMENSAT
 #endif
 



More information about the libcxx-commits mailing list