CopyFile: add a C++ API

Having to swizzle to C strings all the time is a bit annoying.

Change-Id: I0b80877706e32e873e567685f6b471745da70311
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/2396557
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Mike Frysinger 2020-09-07 17:29:40 -04:00
parent c6d49c47a0
commit 5640e57f1f
3 changed files with 8 additions and 1 deletions

View file

@ -521,7 +521,7 @@ TEST(MinidumpWriterTest, DeletedBinary) {
// Copy binary to a temp file. // Copy binary to a temp file.
AutoTempDir temp_dir; AutoTempDir temp_dir;
string binpath = temp_dir.path() + "/linux-dumper-unittest-helper"; string binpath = temp_dir.path() + "/linux-dumper-unittest-helper";
ASSERT_TRUE(CopyFile(helper_path.c_str(), binpath.c_str())) ASSERT_TRUE(CopyFile(helper_path, binpath))
<< "Failed to copy " << helper_path << " to " << binpath; << "Failed to copy " << helper_path << " to " << binpath;
ASSERT_EQ(0, chmod(binpath.c_str(), 0755)); ASSERT_EQ(0, chmod(binpath.c_str(), 0755));

View file

@ -96,6 +96,10 @@ bool CopyFile(const char* from_path, const char* to_path) {
return result; return result;
} }
bool CopyFile(const std::string& from_path, const std::string& to_path) {
return CopyFile(from_path.c_str(), to_path.c_str());
}
bool ReadFile(const char* path, void* buffer, ssize_t* buffer_size) { bool ReadFile(const char* path, void* buffer, ssize_t* buffer_size) {
int fd = HANDLE_EINTR(open(path, O_RDONLY)); int fd = HANDLE_EINTR(open(path, O_RDONLY));
if (fd == -1) { if (fd == -1) {

View file

@ -33,9 +33,12 @@
#ifndef COMMON_TESTS_FILE_UTILS_H_ #ifndef COMMON_TESTS_FILE_UTILS_H_
#define COMMON_TESTS_FILE_UTILS_H_ #define COMMON_TESTS_FILE_UTILS_H_
#include <string>
namespace google_breakpad { namespace google_breakpad {
// Copies a file from |from_path| to |to_path|. Returns true on success. // Copies a file from |from_path| to |to_path|. Returns true on success.
bool CopyFile(const std::string& from_path, const std::string& to_path);
bool CopyFile(const char* from_path, const char* to_path); bool CopyFile(const char* from_path, const char* to_path);
// Reads the content of a file at |path| into |buffer|. |buffer_size| specifies // Reads the content of a file at |path| into |buffer|. |buffer_size| specifies