fileio: Replace assert with tprintf() and exit(1)

Assertions are good for programming errors, but not for wrong user input.

The new code no longer needs File::ReadFileToStringOrDie, so remove that
method.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2016-08-16 07:12:47 +02:00
parent d093ed40cc
commit 6ec1a0a09b
3 changed files with 4 additions and 8 deletions

View File

@ -80,12 +80,6 @@ bool File::ReadFileToString(const string& filename, string* out) {
return in.CloseFile();
}
void File::ReadFileToStringOrDie(const string& filename, string* out) {
ASSERT_HOST_MSG(ReadFileToString(filename, out),
"Failed to read file: %s\n", filename.c_str());
}
string File::JoinPath(const string& prefix, const string& suffix) {
return (!prefix.size() || prefix[prefix.size() - 1] == '/') ?
prefix + suffix : prefix + "/" + suffix;

View File

@ -42,7 +42,6 @@ class File {
// Return true if the file 'filename' is readable.
static bool Readable(const string& filename);
static void ReadFileToStringOrDie(const string& filename, string* out);
static bool ReadFileToString(const string& filename, string* out);
// Helper methods

View File

@ -499,7 +499,10 @@ int main(int argc, char** argv) {
string src_utf8;
// This c_str is NOT redundant!
File::ReadFileToStringOrDie(FLAGS_text.c_str(), &src_utf8);
if (!File::ReadFileToString(FLAGS_text.c_str(), &src_utf8)) {
tprintf("Failed to read file: %s\n", FLAGS_text.c_str());
exit(1);
}
// Remove the unicode mark if present.
if (strncmp(src_utf8.c_str(), "\xef\xbb\xbf", 3) == 0) {