@matheusbsbs / matheus-bagliano / commits / 8b1f6de854
Fork 0

copy.c: copy_fd - correctly report write errors

Previously, the errno could have been lost due to an intervening close() call. This patch also contains minor cosmetic changes. Signed-off-by: Ariel Badichi <abadichi@bezeqint.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ariel Badichi committed Apr 23, 2008 at 04:05 UTC 8b1f6de854ae95eb3f4225a71aad29ca086cfd2e
1 file changed +4 -4
copy.c
+4 -4
@@ -9,8 +9,7 @@ int copy_fd(int ifd, int ofd)
9 if (!len)
10 break;
11 if (len < 0) {
12 - int read_error;
13 - read_error = errno;
12 + int read_error = errno;
13 close(ifd);
14 return error("copy-fd: read returned %s",
15 strerror(read_error));
@@ -25,9 +24,10 @@ int copy_fd(int ifd, int ofd)
24 close(ifd);
25 return error("copy-fd: write returned 0");
26 } else {
27 + int write_error = errno;
28 close(ifd);
29 return error("copy-fd: write returned %s",
30 - strerror(errno));
30 + strerror(write_error));
31 }
32 }
33 }
@@ -48,7 +48,7 @@ int copy_file(const char *dst, const char *src, int mode)
48 }
49 status = copy_fd(fdi, fdo);
50 if (close(fdo) != 0)
51 - return error("%s: write error: %s", dst, strerror(errno));
51 + return error("%s: close error: %s", dst, strerror(errno));
52
53 if (!status && adjust_shared_perm(dst))
54 return -1;