Index: third_party/protobuf/src/google/protobuf/testing/file.cc |
diff --git a/third_party/protobuf/src/google/protobuf/testing/file.cc b/third_party/protobuf/src/google/protobuf/testing/file.cc |
index e224781db572fc19e1a90a99c7201c243077e588..3d07b1276cf96698f95b367d65999de5e6eb2362 100644 |
--- a/third_party/protobuf/src/google/protobuf/testing/file.cc |
+++ b/third_party/protobuf/src/google/protobuf/testing/file.cc |
@@ -1,6 +1,6 @@ |
// Protocol Buffers - Google's data interchange format |
// Copyright 2008 Google Inc. All rights reserved. |
-// http://code.google.com/p/protobuf/ |
+// https://developers.google.com/protocol-buffers/ |
// |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
@@ -82,6 +82,24 @@ void File::ReadFileToStringOrDie(const string& name, string* output) { |
GOOGLE_CHECK(ReadFileToString(name, output)) << "Could not read: " << name; |
} |
+bool File::WriteStringToFile(const string& contents, const string& name) { |
+ FILE* file = fopen(name.c_str(), "wb"); |
+ if (file == NULL) { |
+ GOOGLE_LOG(ERROR) << "fopen(" << name << ", \"wb\"): " << strerror(errno); |
+ return false; |
+ } |
+ |
+ if (fwrite(contents.data(), 1, contents.size(), file) != contents.size()) { |
+ GOOGLE_LOG(ERROR) << "fwrite(" << name << "): " << strerror(errno); |
+ return false; |
+ } |
+ |
+ if (fclose(file) != 0) { |
+ return false; |
+ } |
+ return true; |
+} |
+ |
void File::WriteStringToFileOrDie(const string& contents, const string& name) { |
FILE* file = fopen(name.c_str(), "wb"); |
GOOGLE_CHECK(file != NULL) |
@@ -115,6 +133,8 @@ bool File::RecursivelyCreateDir(const string& path, int mode) { |
void File::DeleteRecursively(const string& name, |
void* dummy1, void* dummy2) { |
+ if (name.empty()) return; |
+ |
// We don't care too much about error checking here since this is only used |
// in tests to delete temporary directories that are under /tmp anyway. |
@@ -172,5 +192,9 @@ void File::DeleteRecursively(const string& name, |
#endif |
} |
+bool File::ChangeWorkingDirectory(const string& new_working_directory) { |
+ return chdir(new_working_directory.c_str()) == 0; |
+} |
+ |
} // namespace protobuf |
} // namespace google |