Skip to content

Commit 8b1f6de

Browse files
Ariel Badichigitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 82881b3 commit 8b1f6de

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

copy.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ int copy_fd(int ifd, int ofd)
99
if (!len)
1010
break;
1111
if (len < 0) {
12-
int read_error;
13-
read_error = errno;
12+
int read_error = errno;
1413
close(ifd);
1514
return error("copy-fd: read returned %s",
1615
strerror(read_error));
@@ -25,9 +24,10 @@ int copy_fd(int ifd, int ofd)
2524
close(ifd);
2625
return error("copy-fd: write returned 0");
2726
} else {
27+
int write_error = errno;
2828
close(ifd);
2929
return error("copy-fd: write returned %s",
30-
strerror(errno));
30+
strerror(write_error));
3131
}
3232
}
3333
}
@@ -48,7 +48,7 @@ int copy_file(const char *dst, const char *src, int mode)
4848
}
4949
status = copy_fd(fdi, fdo);
5050
if (close(fdo) != 0)
51-
return error("%s: write error: %s", dst, strerror(errno));
51+
return error("%s: close error: %s", dst, strerror(errno));
5252

5353
if (!status && adjust_shared_perm(dst))
5454
return -1;

0 commit comments

Comments
 (0)