Simplify io_write_newline error handling

Instead of returning the number of bytes written, which are platform specific, return `true` on success and `false` on failure, so no platform specific code is required when checking the result.
This commit is contained in:
Robert Müller 2023-02-18 14:13:55 +01:00
parent 51c5567fc0
commit 3173aeec6a
3 changed files with 9 additions and 11 deletions

View file

@ -364,12 +364,12 @@ unsigned io_write(IOHANDLE io, const void *buffer, unsigned size)
return fwrite(buffer, 1, size, (FILE *)io);
}
unsigned io_write_newline(IOHANDLE io)
bool io_write_newline(IOHANDLE io)
{
#if defined(CONF_FAMILY_WINDOWS)
return fwrite("\r\n", 1, 2, (FILE *)io);
return io_write(io, "\r\n", 2) == 2;
#else
return fwrite("\n", 1, 1, (FILE *)io);
return io_write(io, "\n", 1) == 1;
#endif
}

View file

@ -296,15 +296,15 @@ unsigned io_skip(IOHANDLE io, int size);
unsigned io_write(IOHANDLE io, const void *buffer, unsigned size);
/**
* Writes newline to file.
* Writes a platform dependent newline to file.
*
* @ingroup File-IO
*
* @param io Handle to the file.
*
* @return Number of bytes written.
* @return true on success, false on failure.
*/
unsigned io_write_newline(IOHANDLE io);
bool io_write_newline(IOHANDLE io);
/**
* Seeks to a specified offset in the file.

View file

@ -147,12 +147,10 @@ void CConfigManager::WriteLine(const char *pLine)
{
if(!m_ConfigFile ||
io_write(m_ConfigFile, pLine, str_length(pLine)) != static_cast<unsigned>(str_length(pLine)) ||
#if defined(CONF_FAMILY_WINDOWS)
io_write_newline(m_ConfigFile) != 2)
#else
io_write_newline(m_ConfigFile) != 1)
#endif
!io_write_newline(m_ConfigFile))
{
m_Failed = true;
}
}
IConfigManager *CreateConfigManager() { return new CConfigManager; }