]>
git.ipfire.org Git - thirdparty/git.git/blob - copy.c
1 #include "git-compat-util.h"
5 int copy_fd(int ifd
, int ofd
)
9 ssize_t len
= xread(ifd
, buffer
, sizeof(buffer
));
13 return COPY_READ_ERROR
;
14 if (write_in_full(ofd
, buffer
, len
) < 0)
15 return COPY_WRITE_ERROR
;
20 static int copy_times(const char *dst
, const char *src
)
24 if (stat(src
, &st
) < 0)
26 times
.actime
= st
.st_atime
;
27 times
.modtime
= st
.st_mtime
;
28 if (utime(dst
, ×
) < 0)
33 int copy_file(const char *dst
, const char *src
, int mode
)
37 mode
= (mode
& 0111) ? 0777 : 0666;
38 if ((fdi
= open(src
, O_RDONLY
)) < 0)
40 if ((fdo
= open(dst
, O_WRONLY
| O_CREAT
| O_EXCL
, mode
)) < 0) {
44 status
= copy_fd(fdi
, fdo
);
47 error_errno("copy-fd: read returned");
49 case COPY_WRITE_ERROR
:
50 error_errno("copy-fd: write returned");
55 return error_errno("%s: close error", dst
);
57 if (!status
&& adjust_shared_perm(dst
))
63 int copy_file_with_time(const char *dst
, const char *src
, int mode
)
65 int status
= copy_file(dst
, src
, mode
);
67 return copy_times(dst
, src
);