1 #include "git-compat-util.h"
6 int copy_fd(int ifd
, int ofd
)
10 ssize_t len
= xread(ifd
, buffer
, sizeof(buffer
));
14 return COPY_READ_ERROR
;
15 if (write_in_full(ofd
, buffer
, len
) < 0)
16 return COPY_WRITE_ERROR
;
21 static int copy_times(const char *dst
, const char *src
)
25 if (stat(src
, &st
) < 0)
27 times
.actime
= st
.st_atime
;
28 times
.modtime
= st
.st_mtime
;
29 if (utime(dst
, ×
) < 0)
34 int copy_file(const char *dst
, const char *src
, int mode
)
38 mode
= (mode
& 0111) ? 0777 : 0666;
39 if ((fdi
= open(src
, O_RDONLY
)) < 0)
41 if ((fdo
= open(dst
, O_WRONLY
| O_CREAT
| O_EXCL
, mode
)) < 0) {
45 status
= copy_fd(fdi
, fdo
);
48 error_errno("copy-fd: read returned");
50 case COPY_WRITE_ERROR
:
51 error_errno("copy-fd: write returned");
56 return error_errno("%s: close error", dst
);
58 if (!status
&& adjust_shared_perm(dst
))
64 int copy_file_with_time(const char *dst
, const char *src
, int mode
)
66 int status
= copy_file(dst
, src
, mode
);
68 return copy_times(dst
, src
);