[Lldb-commits] [lldb] r298375 - Replace std::ofstream with llvm::raw_fd_ostream
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Mar 21 06:49:50 PDT 2017
Author: labath
Date: Tue Mar 21 08:49:50 2017
New Revision: 298375
URL: http://llvm.org/viewvc/llvm-project?rev=298375&view=rev
Log:
Replace std::ofstream with llvm::raw_fd_ostream
Summary:
ofstream does not handle paths with non-ascii characters correctly on
windows, so I am switching these to llvm streams to fix that.
Reviewers: zturner, eugene
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D31079
Modified:
lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp
lldb/trunk/source/Target/Platform.cpp
lldb/trunk/tools/lldb-server/lldb-platform.cpp
Modified: lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp?rev=298375&r1=298374&r2=298375&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp Tue Mar 21 08:49:50 2017
@@ -402,13 +402,14 @@ Error AdbClient::ShellToFile(const char
return error;
const auto output_filename = output_file_spec.GetPath();
- std::ofstream dst(output_filename, std::ios::out | std::ios::binary);
- if (!dst.is_open())
+ std::error_code EC;
+ llvm::raw_fd_ostream dst(output_filename, EC, llvm::sys::fs::F_None);
+ if (EC)
return Error("Unable to open local file %s", output_filename.c_str());
dst.write(&output_buffer[0], output_buffer.size());
dst.close();
- if (!dst)
+ if (dst.has_error())
return Error("Failed to write file %s", output_filename.c_str());
return Error();
}
@@ -428,8 +429,9 @@ Error AdbClient::SyncService::internalPu
const auto local_file_path = local_file.GetPath();
llvm::FileRemover local_file_remover(local_file_path);
- std::ofstream dst(local_file_path, std::ios::out | std::ios::binary);
- if (!dst.is_open())
+ std::error_code EC;
+ llvm::raw_fd_ostream dst(local_file_path, EC, llvm::sys::fs::F_None);
+ if (EC)
return Error("Unable to open local file %s", local_file_path.c_str());
const auto remote_file_path = remote_file.GetPath(false);
@@ -447,6 +449,9 @@ Error AdbClient::SyncService::internalPu
if (!eof)
dst.write(&chunk[0], chunk.size());
}
+ dst.close();
+ if (dst.has_error())
+ return Error("Failed to write file %s", local_file_path.c_str());
local_file_remover.releaseFile();
return error;
Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=298375&r1=298374&r2=298375&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Tue Mar 21 08:49:50 2017
@@ -1645,8 +1645,9 @@ Error Platform::DownloadModuleSlice(cons
const FileSpec &dst_file_spec) {
Error error;
- std::ofstream dst(dst_file_spec.GetPath(), std::ios::out | std::ios::binary);
- if (!dst.is_open()) {
+ std::error_code EC;
+ llvm::raw_fd_ostream dst(dst_file_spec.GetPath(), EC, llvm::sys::fs::F_None);
+ if (EC) {
error.SetErrorStringWithFormat("unable to open destination file: %s",
dst_file_spec.GetPath().c_str());
return error;
Modified: lldb/trunk/tools/lldb-server/lldb-platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-server/lldb-platform.cpp?rev=298375&r1=298374&r2=298375&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-server/lldb-platform.cpp (original)
+++ lldb/trunk/tools/lldb-server/lldb-platform.cpp Tue Mar 21 08:49:50 2017
@@ -106,23 +106,25 @@ static Error save_socket_id_to_file(cons
return Error("Failed to create directory %s: %s",
temp_file_spec.GetCString(), error.AsCString());
- llvm::SmallString<PATH_MAX> temp_file_path;
+ llvm::SmallString<64> temp_file_path;
temp_file_spec.AppendPathComponent("port-file.%%%%%%");
- auto err_code = llvm::sys::fs::createUniqueFile(temp_file_spec.GetCString(),
+ int FD;
+ auto err_code = llvm::sys::fs::createUniqueFile(temp_file_spec.GetPath(), FD,
temp_file_path);
if (err_code)
return Error("Failed to create temp file: %s", err_code.message().c_str());
- llvm::FileRemover tmp_file_remover(temp_file_path.c_str());
+ llvm::FileRemover tmp_file_remover(temp_file_path);
{
- std::ofstream temp_file(temp_file_path.c_str(), std::ios::out);
- if (!temp_file.is_open())
- return Error("Failed to open temp file %s", temp_file_path.c_str());
+ llvm::raw_fd_ostream temp_file(FD, true);
temp_file << socket_id;
+ temp_file.close();
+ if (temp_file.has_error())
+ return Error("Failed to write to port file.");
}
- err_code = llvm::sys::fs::rename(temp_file_path.c_str(), file_spec.GetPath());
+ err_code = llvm::sys::fs::rename(temp_file_path, file_spec.GetPath());
if (err_code)
return Error("Failed to rename file %s to %s: %s", temp_file_path.c_str(),
file_spec.GetPath().c_str(), err_code.message().c_str());
More information about the lldb-commits
mailing list