Skip to content

Commit

Permalink
Merge branch 'jk/strbuf-read-file-close-error'
Browse files Browse the repository at this point in the history
Code clean-up.

* jk/strbuf-read-file-close-error:
  strbuf_read_file(): preserve errno across close() call
  • Loading branch information
gitster committed Mar 6, 2018
2 parents 169c9c0 + 79f0ba1 commit 6c3e6f6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion strbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,14 +612,18 @@ ssize_t strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)
{
int fd;
ssize_t len;
int saved_errno;

fd = open(path, O_RDONLY);
if (fd < 0)
return -1;
len = strbuf_read(sb, fd, hint);
saved_errno = errno;
close(fd);
if (len < 0)
if (len < 0) {
errno = saved_errno;
return -1;
}

return len;
}
Expand Down

0 comments on commit 6c3e6f6

Please sign in to comment.