libutil: fix util_file_write_* return code

By default, files opened via fopen are block-buffered. As a result,
I/O errors that occur during file write operations via util_file_write_*
are silently ignored because fputs() only buffers data while actual I/O
occurs during the flush operation that is part of the final fclose()
library call.

Fix this by indicating errors that occur during fclose() via the
util_file_write_* function return code.

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
Peter Oberparleiter
2024-02-05 14:40:25 +01:00
committed by Steffen Eiden
parent fb0b6263d1
commit a97a8f1cba

View File

@@ -110,7 +110,8 @@ static int file_puts(const char *str, const char *path)
}
rc = 0;
out_fclose:
fclose(fp);
if (fclose(fp))
return -1;
return rc;
}