xbolva00 updated this revision to Diff 163706.
xbolva00 added a comment.

- Removed include errno.h


https://reviews.llvm.org/D51591

Files:
  source/Host/common/PseudoTerminal.cpp

Index: source/Host/common/PseudoTerminal.cpp
===================================================================
--- source/Host/common/PseudoTerminal.cpp
+++ source/Host/common/PseudoTerminal.cpp
@@ -10,7 +10,8 @@
 #include "lldb/Host/PseudoTerminal.h"
 #include "lldb/Host/Config.h"
 
-#include <errno.h>
+#include "llvm/Support/Errno.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -84,26 +85,33 @@
     error_str[0] = '\0';
 
 #if !defined(LLDB_DISABLE_POSIX)
+  std::string strerror;
   // Open the master side of a pseudo terminal
   m_master_fd = ::posix_openpt(oflag);
   if (m_master_fd < 0) {
-    if (error_str)
-      ::strerror_r(errno, error_str, error_len);
+    if (error_str) {
+      strerror = llvm::sys::StrError();
+      ::snprintf(error_str, error_len, "%s", strerror.c_str());
+    }
     return false;
   }
 
   // Grant access to the slave pseudo terminal
   if (::grantpt(m_master_fd) < 0) {
-    if (error_str)
-      ::strerror_r(errno, error_str, error_len);
+    if (error_str) {
+      strerror = llvm::sys::StrError();
+      ::snprintf(error_str, error_len, "%s", strerror.c_str());
+    }
     CloseMasterFileDescriptor();
     return false;
   }
 
   // Clear the lock flag on the slave pseudo terminal
   if (::unlockpt(m_master_fd) < 0) {
-    if (error_str)
-      ::strerror_r(errno, error_str, error_len);
+    if (error_str) {
+      strerror = llvm::sys::StrError();
+      ::snprintf(error_str, error_len, "%s", strerror.c_str());
+    }
     CloseMasterFileDescriptor();
     return false;
   }
@@ -131,6 +139,7 @@
   if (error_str)
     error_str[0] = '\0';
 
+  std::string strerror;
   CloseSlaveFileDescriptor();
 
   // Open the master side of a pseudo terminal
@@ -142,8 +151,10 @@
   m_slave_fd = ::open(slave_name, oflag);
 
   if (m_slave_fd < 0) {
-    if (error_str)
-      ::strerror_r(errno, error_str, error_len);
+    if (error_str) {
+      strerror = llvm::sys::StrError();
+      ::snprintf(error_str, error_len, "%s", strerror.c_str());
+    }
     return false;
   }
 
@@ -166,16 +177,19 @@
   if (error_str)
     error_str[0] = '\0';
 
+  std::string strerror;
   if (m_master_fd < 0) {
     if (error_str)
       ::snprintf(error_str, error_len, "%s",
                  "master file descriptor is invalid");
     return nullptr;
   }
   const char *slave_name = ::ptsname(m_master_fd);
 
-  if (error_str && slave_name == nullptr)
-    ::strerror_r(errno, error_str, error_len);
+  if (error_str && slave_name == nullptr) {
+    strerror = llvm::sys::StrError();
+    ::snprintf(error_str, error_len, "%s", strerror.c_str());
+  }
 
   return slave_name;
 }
@@ -204,16 +218,19 @@
     error_str[0] = '\0';
   pid_t pid = LLDB_INVALID_PROCESS_ID;
 #if !defined(LLDB_DISABLE_POSIX)
+  std::string strerror;
   int flags = O_RDWR;
   flags |= O_CLOEXEC;
   if (OpenFirstAvailableMaster(flags, error_str, error_len)) {
     // Successfully opened our master pseudo terminal
 
     pid = ::fork();
     if (pid < 0) {
       // Fork failed
-      if (error_str)
-        ::strerror_r(errno, error_str, error_len);
+      if (error_str) {
+        strerror = llvm::sys::StrError();
+        ::snprintf(error_str, error_len, "%s", strerror.c_str());
+      }
     } else if (pid == 0) {
       // Child Process
       ::setsid();
@@ -228,24 +245,32 @@
 #if defined(TIOCSCTTY)
         // Acquire the controlling terminal
         if (::ioctl(m_slave_fd, TIOCSCTTY, (char *)0) < 0) {
-          if (error_str)
-            ::strerror_r(errno, error_str, error_len);
+          if (error_str) {
+            strerror = llvm::sys::StrError();
+            ::snprintf(error_str, error_len, "%s", strerror.c_str());
+          }
         }
 #endif
         // Duplicate all stdio file descriptors to the slave pseudo terminal
         if (::dup2(m_slave_fd, STDIN_FILENO) != STDIN_FILENO) {
-          if (error_str && !error_str[0])
-            ::strerror_r(errno, error_str, error_len);
+          if (error_str && !error_str[0]) {
+            strerror = llvm::sys::StrError();
+            ::snprintf(error_str, error_len, "%s", strerror.c_str());
+          }
         }
 
         if (::dup2(m_slave_fd, STDOUT_FILENO) != STDOUT_FILENO) {
-          if (error_str && !error_str[0])
-            ::strerror_r(errno, error_str, error_len);
+          if (error_str && !error_str[0]) {
+            strerror = llvm::sys::StrError();
+            ::snprintf(error_str, error_len, "%s", strerror.c_str());
+          }
         }
 
         if (::dup2(m_slave_fd, STDERR_FILENO) != STDERR_FILENO) {
-          if (error_str && !error_str[0])
-            ::strerror_r(errno, error_str, error_len);
+          if (error_str && !error_str[0]) {
+            strerror = llvm::sys::StrError();
+            ::snprintf(error_str, error_len, "%s", strerror.c_str());
+          }
         }
       }
     } else {
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to