Documentation: format-patch
[git/git.git] / copy.c
CommitLineData
f3123c4a
JH
1#include "cache.h"
2
3int copy_fd(int ifd, int ofd)
4{
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 if (errno == EAGAIN)
14 continue;
15 return error("copy-fd: read returned %s",
16 strerror(errno));
17 }
18 while (1) {
19 int written = write(ofd, buf, len);
20 if (written > 0) {
21 buf += written;
22 len -= written;
23 if (!len)
24 break;
25 }
26 if (!written)
27 return error("copy-fd: write returned 0");
28 if (errno == EAGAIN || errno == EINTR)
29 continue;
30 return error("copy-fd: write returned %s",
31 strerror(errno));
32 }
33 }
34 close(ifd);
35 return 0;
36}
37