summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Host/windows/PosixApi.h1
-rw-r--r--lldb/source/Host/windows/Windows.cpp27
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp8
-rw-r--r--lldb/source/Target/Platform.cpp8
-rw-r--r--lldb/source/Target/ProcessLaunchInfo.cpp7
-rw-r--r--lldb/source/Target/TargetList.cpp20
6 files changed, 22 insertions, 49 deletions
diff --git a/lldb/include/lldb/Host/windows/PosixApi.h b/lldb/include/lldb/Host/windows/PosixApi.h
index 4f257378162..f9efa9e5836 100644
--- a/lldb/include/lldb/Host/windows/PosixApi.h
+++ b/lldb/include/lldb/Host/windows/PosixApi.h
@@ -82,7 +82,6 @@ char *strcasestr(const char *s, const char *find);
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);
diff --git a/lldb/source/Host/windows/Windows.cpp b/lldb/source/Host/windows/Windows.cpp
index 21afc6d85da..ee965e78603 100644
--- a/lldb/source/Host/windows/Windows.cpp
+++ b/lldb/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 @@ char *basename(char *path) {
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); }
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
index 11069749186..d3161838ed3 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -356,12 +356,12 @@ GDBRemoteCommunicationServerPlatform::Handle_qGetWorkingDir(
// 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());
}
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index d8db53663f1..4f285e09807 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -523,11 +523,11 @@ void Platform::AddClangModuleCompilationOptions(
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();
diff --git a/lldb/source/Target/ProcessLaunchInfo.cpp b/lldb/source/Target/ProcessLaunchInfo.cpp
index 92d9371b541..334a43eb9c1 100644
--- a/lldb/source/Target/ProcessLaunchInfo.cpp
+++ b/lldb/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 @@ bool ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell(
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;
diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp
index 0637cffddcc..4b2730fa8e2 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 @@ Error TargetList::CreateTargetInternal(Debugger &debugger,
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;
}
OpenPOWER on IntegriCloud