Add to documentation of git-update-index arguments and usage.
[git/dscho.git] / copy.c
blob20092757d395dfa4af99a6062e5e2cc0fa5e00c3
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 if (errno == EAGAIN)
14 continue;
15 return error("copy-fd: read returned %s",
16 strerror(errno));
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;
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));
34 close(ifd);
35 return 0;