diff options
Diffstat (limited to 'src/google/protobuf/testing')
-rw-r--r-- | src/google/protobuf/testing/file.cc | 4 | ||||
-rw-r--r-- | src/google/protobuf/testing/file.h | 7 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/google/protobuf/testing/file.cc b/src/google/protobuf/testing/file.cc index 26cb0a67..def92a00 100644 --- a/src/google/protobuf/testing/file.cc +++ b/src/google/protobuf/testing/file.cc @@ -69,9 +69,9 @@ bool File::Exists(const string& name) { return access(name.c_str(), F_OK) == 0; } -bool File::ReadFileToString(const string& name, string* output) { +bool File::ReadFileToString(const string& name, string* output, bool text_mode) { char buffer[1024]; - FILE* file = fopen(name.c_str(), "rb"); + FILE* file = fopen(name.c_str(), text_mode ? "rt" : "rb"); if (file == NULL) return false; while (true) { diff --git a/src/google/protobuf/testing/file.h b/src/google/protobuf/testing/file.h index 2f63f80e..45989967 100644 --- a/src/google/protobuf/testing/file.h +++ b/src/google/protobuf/testing/file.h @@ -50,7 +50,7 @@ class File { // Read an entire file to a string. Return true if successful, false // otherwise. - static bool ReadFileToString(const string& name, string* output); + static bool ReadFileToString(const string& name, string* output, bool text_mode = false); // Same as above, but crash on failure. static void ReadFileToStringOrDie(const string& name, string* output); @@ -85,6 +85,11 @@ class File { return ReadFileToString(name, output); } + static bool GetContentsAsText( + const string& name, string* output, bool /*is_default*/) { + return ReadFileToString(name, output, true); + } + static bool SetContents( const string& name, const string& contents, bool /*is_default*/) { return WriteStringToFile(contents, name); |