Allow environment variables to be unset in the processes started by run_command
[git/mingw/j6t.git] / copy.c
blobd340bb253ec35af379c29e71f384e15d6822fb9a
1 #include "cache.h"
3 int copy_fd(int ifd, int ofd)
5 while (1) {
6 char buffer[8192];
7 char *buf = buffer;
8 ssize_t len = xread(ifd, buffer, sizeof(buffer));
9 if (!len)
10 break;
11 if (len < 0) {
12 int read_error;
13 read_error = errno;
14 close(ifd);
15 return error("copy-fd: read returned %s",
16 strerror(read_error));
18 while (len) {
19 int written = xwrite(ofd, buf, len);
20 if (written > 0) {
21 buf += written;
22 len -= written;
24 else if (!written) {
25 close(ifd);
26 return error("copy-fd: write returned 0");
27 } else {
28 close(ifd);
29 return error("copy-fd: write returned %s",
30 strerror(errno));
34 close(ifd);
35 return 0;