This revision was automatically updated to reflect the committed changes.
Closed by commit rL292795: Replace getcwd with the llvm equivalent (authored by 
labath).

Changed prior to commit:
  https://reviews.llvm.org/D28858?vs=84828&id=85399#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28858

Files:
  lldb/trunk/include/lldb/Host/windows/PosixApi.h
  lldb/trunk/source/Host/windows/Windows.cpp
  
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
  lldb/trunk/source/Target/Platform.cpp
  lldb/trunk/source/Target/ProcessLaunchInfo.cpp
  lldb/trunk/source/Target/TargetList.cpp

Index: lldb/trunk/source/Host/windows/Windows.cpp
===================================================================
--- lldb/trunk/source/Host/windows/Windows.cpp
+++ lldb/trunk/source/Host/windows/Windows.cpp
@@ -23,10 +23,9 @@
 #include <stdlib.h>
 #include <string.h>
 
-// These prototypes are defined in <direct.h>, but it also defines chdir() and
-// getcwd(), giving multiply defined errors
+// These prototypes are defined in <direct.h>, but it also defines chdir(),
+// giving multiply defined errors
 extern "C" {
-char *_getcwd(char *buffer, int maxlen);
 int _chdir(const char *path);
 }
 
@@ -190,28 +189,6 @@
   return &l1[1];
 }
 
-// use _getcwd() instead of GetCurrentDirectory() because it updates errno
-char *getcwd(char *path, int max) {
-  assert(path == NULL || max <= PATH_MAX);
-  wchar_t wpath[PATH_MAX];
-  if (wchar_t *wresult = _wgetcwd(wpath, PATH_MAX)) {
-    // Caller is allowed to pass in NULL for `path`.
-    // In that case, we're supposed to allocate a
-    // buffer on the caller's behalf.
-    if (path == NULL) {
-      max = UNI_MAX_UTF8_BYTES_PER_CODE_POINT * wcslen(wresult) + 1;
-      path = (char *)malloc(max);
-      if (path == NULL) {
-        errno = ENOMEM;
-        return NULL;
-      }
-    }
-    if (wideToUtf8(wresult, path, max))
-      return path;
-  }
-  return NULL;
-}
-
 // use _chdir() instead of SetCurrentDirectory() because it updates errno
 int chdir(const char *path) { return _chdir(path); }
 
Index: lldb/trunk/source/Target/TargetList.cpp
===================================================================
--- lldb/trunk/source/Target/TargetList.cpp
+++ lldb/trunk/source/Target/TargetList.cpp
@@ -7,11 +7,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// C Includes
-// C++ Includes
-// Other libraries and framework includes
-#include "llvm/ADT/SmallString.h"
-
 // Project includes
 #include "lldb/Core/Broadcaster.h"
 #include "lldb/Core/Debugger.h"
@@ -29,6 +24,10 @@
 #include "lldb/Target/Process.h"
 #include "lldb/Target/TargetList.h"
 
+// Other libraries and framework includes
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/FileSystem.h"
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -369,12 +368,11 @@
     if (file.IsRelative() && !user_exe_path.empty()) {
       // Ignore paths that start with "./" and "../"
       if (!user_exe_path.startswith("./") && !user_exe_path.startswith("../")) {
-        char cwd[PATH_MAX];
-        if (getcwd(cwd, sizeof(cwd))) {
-          std::string cwd_user_exe_path(cwd);
-          cwd_user_exe_path += '/';
-          cwd_user_exe_path += user_exe_path;
-          FileSpec cwd_file(cwd_user_exe_path, false);
+        llvm::SmallString<64> cwd;
+        if (! llvm::sys::fs::current_path(cwd)) {
+          cwd += '/';
+          cwd += user_exe_path;
+          FileSpec cwd_file(cwd, false);
           if (cwd_file.Exists())
             file = cwd_file;
         }
Index: lldb/trunk/source/Target/ProcessLaunchInfo.cpp
===================================================================
--- lldb/trunk/source/Target/ProcessLaunchInfo.cpp
+++ lldb/trunk/source/Target/ProcessLaunchInfo.cpp
@@ -23,6 +23,7 @@
 #include "lldb/Target/Target.h"
 
 #include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/FileSystem.h"
 
 #if !defined(_WIN32)
 #include <limits.h>
@@ -368,10 +369,8 @@
           if (working_dir) {
             new_path += working_dir.GetPath();
           } else {
-            char current_working_dir[PATH_MAX];
-            const char *cwd =
-                getcwd(current_working_dir, sizeof(current_working_dir));
-            if (cwd && cwd[0])
+            llvm::SmallString<64> cwd;
+            if (! llvm::sys::fs::current_path(cwd))
               new_path += cwd;
           }
           std::string curr_path;
Index: lldb/trunk/source/Target/Platform.cpp
===================================================================
--- lldb/trunk/source/Target/Platform.cpp
+++ lldb/trunk/source/Target/Platform.cpp
@@ -523,11 +523,11 @@
 
 FileSpec Platform::GetWorkingDirectory() {
   if (IsHost()) {
-    char cwd[PATH_MAX];
-    if (getcwd(cwd, sizeof(cwd)))
-      return FileSpec{cwd, true};
-    else
+    llvm::SmallString<64> cwd;
+    if (llvm::sys::fs::current_path(cwd))
       return FileSpec{};
+    else
+      return FileSpec(cwd, true);
   } else {
     if (!m_working_dir)
       m_working_dir = GetRemoteWorkingDirectory();
Index: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
===================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -356,12 +356,12 @@
   // If this packet is sent to a platform, then change the current working
   // directory
 
-  char cwd[PATH_MAX];
-  if (getcwd(cwd, sizeof(cwd)) == NULL)
-    return SendErrorResponse(errno);
+  llvm::SmallString<64> cwd;
+  if (std::error_code ec = llvm::sys::fs::current_path(cwd))
+    return SendErrorResponse(ec.value());
 
   StreamString response;
-  response.PutBytesAsRawHex8(cwd, strlen(cwd));
+  response.PutBytesAsRawHex8(cwd.data(), cwd.size());
   return SendPacketNoLock(response.GetString());
 }
 
Index: lldb/trunk/include/lldb/Host/windows/PosixApi.h
===================================================================
--- lldb/trunk/include/lldb/Host/windows/PosixApi.h
+++ lldb/trunk/include/lldb/Host/windows/PosixApi.h
@@ -82,7 +82,6 @@
 char *realpath(const char *name, char *resolved);
 
 int usleep(uint32_t useconds);
-char *getcwd(char *path, int max);
 int chdir(const char *path);
 char *basename(char *path);
 char *dirname(char *path);
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to