Always write and read wrap files in binary mode to prevent writing CRLF line endings on windows (messes up expected unit test files)

release/4.3a0
Richard Roberts 2012-07-17 17:38:29 +00:00
parent e9f710a1ac
commit 10c5ebae73
2 changed files with 2 additions and 2 deletions

View File

@ -35,7 +35,7 @@ void FileWriter::emit(bool add_header, bool force_overwrite) const {
// Only write a file if it is new, an update, or overwrite is forced // Only write a file if it is new, an update, or overwrite is forced
string new_contents = oss.str(); string new_contents = oss.str();
if (force_overwrite || !file_exists || existing_contents != new_contents) { if (force_overwrite || !file_exists || existing_contents != new_contents) {
ofstream ofs(filename_.c_str()); ofstream ofs(filename_.c_str(), ios::binary); // Binary to use LF line endings instead of CRLF
if (!ofs) throw CantOpenFile(filename_); if (!ofs) throw CantOpenFile(filename_);
// header // header

View File

@ -29,7 +29,7 @@ using namespace std;
/* ************************************************************************* */ /* ************************************************************************* */
string file_contents(const string& filename, bool skipheader) { string file_contents(const string& filename, bool skipheader) {
ifstream ifs(filename.c_str()); ifstream ifs(filename.c_str(), ios::binary); // Do not do LF/CRLF translation - we always write in binary mode too
if(!ifs) throw CantOpenFile(filename); if(!ifs) throw CantOpenFile(filename);
// read file into stringstream // read file into stringstream