diff options
author | Ronnie Sahlberg <sahlberg@google.com> | 2014-10-21 12:24:13 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-10-22 14:57:10 -0700 |
commit | 38c401e4bdb8c084bc60f1086b2a905ccb651d75 (patch) | |
tree | 6cd17a6c04e888b538c23b8bd1ad29e715d37e25 | |
parent | 753887912ebe08152fbbf8e4679c9bcecd291dbb (diff) | |
download | git-38c401e4bdb8c084bc60f1086b2a905ccb651d75.tar.gz |
copy.c: make copy_fd preserve meaningful errno
Update copy_fd to return a meaningful errno on failure.
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | copy.c | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -8,12 +8,17 @@ int copy_fd(int ifd, int ofd) if (!len) break; if (len < 0) { - return error("copy-fd: read returned %s", - strerror(errno)); + int save_errno = errno; + error("copy-fd: read returned %s", strerror(errno)); + errno = save_errno; + return -1; + } + if (write_in_full(ofd, buffer, len) < 0) { + int save_errno = errno; + error("copy-fd: write returned %s", strerror(errno)); + errno = save_errno; + return -1; } - if (write_in_full(ofd, buffer, len) < 0) - return error("copy-fd: write returned %s", - strerror(errno)); } return 0; } |