[Lldb-commits] [lldb] r237162 - Windows: fix bug in getcwd() and add chdir().
Ted Woodward
ted.woodward at codeaurora.org
Tue May 12 11:47:33 PDT 2015
Author: ted
Date: Tue May 12 13:47:33 2015
New Revision: 237162
URL: http://llvm.org/viewvc/llvm-project?rev=237162&view=rev
Log:
Windows: fix bug in getcwd() and add chdir().
Summary:
GetCurrentDirectory() returns the number of characters copied; 0 is a failure, not a success.
Add implementation for chdir().
Reviewers: zturner
Reviewed By: zturner
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D9300
Modified:
lldb/trunk/include/lldb/Host/windows/win32.h
lldb/trunk/source/Host/windows/Windows.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
lldb/trunk/source/Target/Platform.cpp
Modified: lldb/trunk/include/lldb/Host/windows/win32.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/windows/win32.h?rev=237162&r1=237161&r2=237162&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/windows/win32.h (original)
+++ lldb/trunk/include/lldb/Host/windows/win32.h Tue May 12 13:47:33 2015
@@ -57,6 +57,7 @@ typedef uint32_t pid_t;
int usleep(uint32_t useconds);
char* getcwd(char* path, int max);
+int chdir(const char* path);
char* basename(char *path);
char *dirname(char *path);
Modified: lldb/trunk/source/Host/windows/Windows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/Windows.cpp?rev=237162&r1=237161&r2=237162&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/Windows.cpp (original)
+++ lldb/trunk/source/Host/windows/Windows.cpp Tue May 12 13:47:33 2015
@@ -20,6 +20,13 @@
#include <cerrno>
#include <ctype.h>
+// These prototypes are defined in <direct.h>, but it also defines chdir() and getcwd(), giving multiply defined errors
+extern "C"
+{
+ char *_getcwd(char *buffer, int maxlen);
+ int _chdir(const char *path);
+}
+
int vasprintf(char **ret, const char *fmt, va_list ap)
{
char *buf;
@@ -157,11 +164,16 @@ char* basename(char *path)
return &l1[1];
}
+// use _getcwd() instead of GetCurrentDirectory() because it updates errno
char* getcwd(char* path, int max)
{
- if (GetCurrentDirectory(max, path) == 0)
- return path;
- return NULL;
+ return _getcwd(path, max);
+}
+
+// use _chdir() instead of SetCurrentDirectory() because it updates errno
+int chdir(const char* path)
+{
+ return _chdir(path);
}
char *dirname(char *path)
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp?rev=237162&r1=237161&r2=237162&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp Tue May 12 13:47:33 2015
@@ -217,15 +217,10 @@ GDBRemoteCommunicationServerPlatform::Ha
std::string path;
packet.GetHexByteString (path);
-#ifdef _WIN32
- // Not implemented on Windows
- return SendUnimplementedResponse ("GDBRemoteCommunicationServerPlatform::Handle_QSetWorkingDir unimplemented");
-#else
// If this packet is sent to a platform, then change the current working directory
if (::chdir(path.c_str()) != 0)
return SendErrorResponse (errno);
return SendOKResponse ();
-#endif
}
GDBRemoteCommunication::PacketResult
Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=237162&r1=237161&r2=237162&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Tue May 12 13:47:33 2015
@@ -875,17 +875,12 @@ Platform::SetWorkingDirectory (const Con
Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
if (log)
log->Printf("Platform::SetWorkingDirectory('%s')", path.GetCString());
-#ifdef _WIN32
- // Not implemented on Windows
- return false;
-#else
if (path)
{
if (chdir(path.GetCString()) == 0)
return true;
}
return false;
-#endif
}
else
{
More information about the lldb-commits
mailing list