diff options
author | Ronnie Sahlberg <sahlberg@google.com> | 2014-11-17 14:14:13 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-11-17 15:05:28 -0800 |
commit | e77884b4c476ca7f6c928de3452a86504e37cf37 (patch) | |
tree | 549e63840acf7178aba330a4ab49d973b96de784 | |
parent | ea4f93eb99038329bbd692c5c8246e5ec8c11da9 (diff) | |
download | git-sb/copy-fd-errno.tar.gz |
copy.c: make copy_fd preserve meaningful errnosb/copy-fd-errnorb/small-pieces-first
Update copy_fd to return a meaningful errno on failure and also
preserve the existing errno variable.
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.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; } |