tvg_saver: fixing file opening mode

Opening files in text mode on windows can
cause issues. Fixed by changeing the mode
to binary.

@Issue: https://github.com/thorvg/thorvg/issues/957
@Issue: https://github.com/thorvg/thorvg/issues/1380
This commit is contained in:
Mira Grudzinska 2023-04-27 16:11:43 +02:00 committed by Hermet Park
parent 84012651cc
commit bce5aef068

View file

@ -170,7 +170,7 @@ bool TvgSaver::saveEncoding(const std::string& path)
memcpy(uncompressed, &compressedSizeBits, TVG_HEADER_COMPRESSED_SIZE_BITS); memcpy(uncompressed, &compressedSizeBits, TVG_HEADER_COMPRESSED_SIZE_BITS);
//Good optimization, flush to file. //Good optimization, flush to file.
auto fp = _fopen(path.c_str(), "w+"); auto fp = _fopen(path.c_str(), "wb+");
if (!fp) goto fail; if (!fp) goto fail;
//write header //write header
@ -193,7 +193,7 @@ fail:
bool TvgSaver::flushTo(const std::string& path) bool TvgSaver::flushTo(const std::string& path)
{ {
auto fp = _fopen(path.c_str(), "w+"); auto fp = _fopen(path.c_str(), "wb+");
if (!fp) return false; if (!fp) return false;
if (fwrite(buffer.data, SIZE(uint8_t), buffer.count, fp) == 0) { if (fwrite(buffer.data, SIZE(uint8_t), buffer.count, fp) == 0) {