1 #include "git-compat-util.h"
8 int copy_fd(int ifd
, int ofd
)
12 ssize_t len
= xread(ifd
, buffer
, sizeof(buffer
));
16 return COPY_READ_ERROR
;
17 if (write_in_full(ofd
, buffer
, len
) < 0)
18 return COPY_WRITE_ERROR
;
23 static int copy_times(const char *dst
, const char *src
)
27 if (stat(src
, &st
) < 0)
29 times
.actime
= st
.st_atime
;
30 times
.modtime
= st
.st_mtime
;
31 if (utime(dst
, ×
) < 0)
36 int copy_file(const char *dst
, const char *src
, int mode
)
40 mode
= (mode
& 0111) ? 0777 : 0666;
41 if ((fdi
= open(src
, O_RDONLY
)) < 0)
43 if ((fdo
= open(dst
, O_WRONLY
| O_CREAT
| O_EXCL
, mode
)) < 0) {
47 status
= copy_fd(fdi
, fdo
);
50 error_errno("copy-fd: read returned");
52 case COPY_WRITE_ERROR
:
53 error_errno("copy-fd: write returned");
58 return error_errno("%s: close error", dst
);
60 if (!status
&& adjust_shared_perm(dst
))
66 int copy_file_with_time(const char *dst
, const char *src
, int mode
)
68 int status
= copy_file(dst
, src
, mode
);
70 return copy_times(dst
, src
);