From: Michael Tremer Date: Sat, 11 May 2024 10:55:46 +0000 (+0100) Subject: writer: Fail if the header could not be written successfully X-Git-Tag: 0.9.18~58 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9106ea854a553c840bb94c43af66cd8c6804dd8a;p=location%2Flibloc.git writer: Fail if the header could not be written successfully Signed-off-by: Michael Tremer --- diff --git a/src/writer.c b/src/writer.c index 13948c2..5ea992b 100644 --- a/src/writer.c +++ b/src/writer.c @@ -643,6 +643,8 @@ END: } LOC_EXPORT int loc_writer_write(struct loc_writer* writer, FILE* f, enum loc_database_version version) { + size_t bytes_written = 0; + // Check version switch (version) { case LOC_DATABASE_VERSION_UNSET: @@ -766,7 +768,11 @@ LOC_EXPORT int loc_writer_write(struct loc_writer* writer, FILE* f, enum loc_dat if (r) return r; - fwrite(&header, 1, sizeof(header), f); + bytes_written = fwrite(&header, 1, sizeof(header), f); + if (bytes_written < sizeof(header)) { + ERROR(writer->ctx, "Could not write header: %s\n", strerror(errno)); + return r; + } // Flush everything fflush(f);