[Lldb-commits] [PATCH] D125995: [lldb] Fix 'ptsname_r' is only available on macOS 10.13.4 or newer

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu May 19 21:40:36 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGea4864007c72: [lldb] Fix 'ptsname_r' is only available on macOS 10.13.4 or newer (authored by JDevlieghere).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125995/new/

https://reviews.llvm.org/D125995

Files:
  lldb/source/Host/common/PseudoTerminal.cpp


Index: lldb/source/Host/common/PseudoTerminal.cpp
===================================================================
--- lldb/source/Host/common/PseudoTerminal.cpp
+++ lldb/source/Host/common/PseudoTerminal.cpp
@@ -22,6 +22,10 @@
 
 #include "lldb/Host/PosixApi.h"
 
+#if defined(__APPLE__)
+#include <Availability.h>
+#endif
+
 #if defined(__ANDROID__)
 int posix_openpt(int flags);
 #endif
@@ -99,21 +103,33 @@
       std::error_code(errno, std::generic_category()));
 }
 
-std::string PseudoTerminal::GetSecondaryName() const {
-  assert(m_primary_fd >= 0);
-#if HAVE_PTSNAME_R
-  char buf[PATH_MAX];
-  buf[0] = '\0';
-  int r = ptsname_r(m_primary_fd, buf, sizeof(buf));
-  (void)r;
-  assert(r == 0);
-  return buf;
-#else
+static std::string use_ptsname(int fd) {
   static std::mutex mutex;
   std::lock_guard<std::mutex> guard(mutex);
-  const char *r = ptsname(m_primary_fd);
+  const char *r = ptsname(fd);
   assert(r != nullptr);
   return r;
+}
+
+std::string PseudoTerminal::GetSecondaryName() const {
+  assert(m_primary_fd >= 0);
+#if HAVE_PTSNAME_R
+#if defined(__APPLE__)
+  if (__builtin_available(macos 10.13.4, iOS 11.3, tvOS 11.3, watchOS 4.4, *)) {
+#endif
+    char buf[PATH_MAX];
+    buf[0] = '\0';
+    int r = ptsname_r(m_primary_fd, buf, sizeof(buf));
+    (void)r;
+    assert(r == 0);
+    return buf;
+#if defined(__APPLE__)
+  } else {
+    return use_ptsname(m_primary_fd);
+  }
+#endif
+#else
+  return use_ptsname(m_primary_fd);
 #endif
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125995.430878.patch
Type: text/x-patch
Size: 1480 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220520/2e5e7a0c/attachment.bin>


More information about the lldb-commits mailing list