提交 3f7ebc6e 编写于 作者: J Junio C Hamano

Merge branch 'jk/tempfile-ferror-fclose-confusion'

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()
......@@ -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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册