Skip to content

Commit

Permalink
report error and exit when writing is failed
Browse files Browse the repository at this point in the history
  • Loading branch information
sfchen committed Jun 20, 2018
1 parent 553b9cc commit ff01054
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,21 @@ bool Writer::writeLine(string& linestr){
const char* line = linestr.c_str();
int size = linestr.length();
int written;
bool status;
bool status = true;
if(mZipped){
written = gzwrite(mZipFile, line, size);
gzputc(mZipFile, '\n');
status = size == written;
if(size > 0 && written == 0)
status = false;
}
else{
mOutStream->write(line, size);
mOutStream->put('\n');
status = !mOutStream->fail();
status = !mOutStream->bad();
}

if(!status) {
error_exit( "Failed to write " + mFilename + ", exiting...");
}

return status;
Expand All @@ -72,14 +77,19 @@ bool Writer::writeString(string& str){
const char* strdata = str.c_str();
int size = str.length();
int written;
bool status;
bool status = true;
if(mZipped){
written = gzwrite(mZipFile, strdata, size);
status = size == written;
if(size > 0 && written == 0)
status = false;
}
else{
mOutStream->write(strdata, size);
status = !mOutStream->fail();
status = !mOutStream->bad();
}

if(!status) {
error_exit( "Failed to write " + mFilename + ", exiting...");
}

return status;
Expand Down

0 comments on commit ff01054

Please sign in to comment.