cwFile.cpp : Added guard to not write if bufByteCnt is 0.

This commit is contained in:
kevin 2023-11-14 07:52:15 -05:00
parent ce55c64a3b
commit d499dfac1c

View File

@ -252,9 +252,12 @@ cw::rc_t cw::file::write( handle_t h, const void* buf, unsigned bufByteCnt )
if( p->lastRC != kOkRC )
return p->lastRC;
errno = 0;
if( fwrite(buf,bufByteCnt,1,p->fp) != 1 )
return p->lastRC = cwLogSysError(kWriteFailRC,errno,"File write failed on '%s'.", cwStringNullGuard(p->fnStr));
if( bufByteCnt )
{
errno = 0;
if( fwrite(buf,bufByteCnt,1,p->fp) != 1 )
return p->lastRC = cwLogSysError(kWriteFailRC,errno,"File write failed on '%s'.", cwStringNullGuard(p->fnStr));
}
return kOkRC;
}