mirror of
https://github.com/git/git
synced 2024-08-28 12:09:19 +00:00
Merge branch 'jk/strbuf-read-file-close-error'
Code clean-up. * jk/strbuf-read-file-close-error: strbuf_read_file(): preserve errno across close() call
This commit is contained in:
commit
6c3e6f6fcb
6
strbuf.c
6
strbuf.c
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue