merge-one-file: make sure we do not mismerge symbolic links.
[git/mingw.git] / copy.c
blobe1cd5d06503d93f6b400a3911e6b61ff327190ca
1 #include "cache.h"
3 int copy_fd(int ifd, int ofd)
5 while (1) {
6 int len;
7 char buffer[8192];
8 char *buf = buffer;
9 len = read(ifd, buffer, sizeof(buffer));
10 if (!len)
11 break;
12 if (len < 0) {
13 int read_error;
14 if (errno == EAGAIN)
15 continue;
16 read_error = errno;
17 close(ifd);
18 return error("copy-fd: read returned %s",
19 strerror(read_error));
21 while (1) {
22 int written = write(ofd, buf, len);
23 if (written > 0) {
24 buf += written;
25 len -= written;
26 if (!len)
27 break;
29 if (!written)
30 return error("copy-fd: write returned 0");
31 if (errno == EAGAIN || errno == EINTR)
32 continue;
33 return error("copy-fd: write returned %s",
34 strerror(errno));
37 close(ifd);
38 return 0;