]> git.ipfire.org Git - thirdparty/git.git/blobdiff - strbuf.c
strbuf_read_file(): preserve errno across close() call
[thirdparty/git.git] / strbuf.c
index 1df674e9194ee6d5cd5386f477745ff6639b7b65..5f138ed3c802c3353578cfe792ae49e235e695a8 100644 (file)
--- a/strbuf.c
+++ b/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;
 }