Merge branch 'jk/tempfile-ferror-fclose-confusion' into maint
A caller of tempfile API that uses stdio interface to write to files may ignore errors while writing, which is detected when tempfile is closed (with a call to ferror()). By that time, the original errno that may have told us what went wrong is likely to be long gone and was overwritten by an irrelevant value. close_tempfile() now resets errno to EIO to make errno at least predictable. * jk/tempfile-ferror-fclose-confusion: tempfile: set errno to a known value before calling ferror()
This commit is contained in:
commit
f63df942a3
@ -247,8 +247,13 @@ int close_tempfile(struct tempfile *tempfile)
|
||||
tempfile->fd = -1;
|
||||
if (fp) {
|
||||
tempfile->fp = NULL;
|
||||
err = ferror(fp);
|
||||
err |= fclose(fp);
|
||||
if (ferror(fp)) {
|
||||
err = -1;
|
||||
if (!fclose(fp))
|
||||
errno = EIO;
|
||||
} else {
|
||||
err = fclose(fp);
|
||||
}
|
||||
} else {
|
||||
err = close(fd);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user