Replace getcwd with the llvm equivalent
Summary:
getcwd() is not available (well.. um.. deprecated?) on windows, and the way
PosixApi.h is providing it causes strange compile errors when it's included in
the wrong order. The best way to avoid that is to just not use chdir.
This replaces all uses of getcwd in generic code. There are still a couple of
more uses, but these are in platform-specific code.
chdir() is causing a similar problem, but for that there is no llvm equivalent
for that (yet).
Reviewers: zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D28858
llvm-svn: 292795
diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp
index 0637cff..4b2730f 100644
--- a/lldb/source/Target/TargetList.cpp
+++ b/lldb/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;
}