4 int copy_fd(int ifd
, int ofd
)
8 ssize_t len
= xread(ifd
, buffer
, sizeof(buffer
));
12 return COPY_READ_ERROR
;
13 if (write_in_full(ofd
, buffer
, len
) < 0)
14 return COPY_WRITE_ERROR
;
19 static int copy_times(const char *dst
, const char *src
)
23 if (stat(src
, &st
) < 0)
25 times
.actime
= st
.st_atime
;
26 times
.modtime
= st
.st_mtime
;
27 if (utime(dst
, ×
) < 0)
32 int copy_file(const char *dst
, const char *src
, int mode
)
36 mode
= (mode
& 0111) ? 0777 : 0666;
37 if ((fdi
= open(src
, O_RDONLY
)) < 0)
39 if ((fdo
= open(dst
, O_WRONLY
| O_CREAT
| O_EXCL
, mode
)) < 0) {
43 status
= copy_fd(fdi
, fdo
);
46 error_errno("copy-fd: read returned");
48 case COPY_WRITE_ERROR
:
49 error_errno("copy-fd: write returned");
54 return error_errno("%s: close error", dst
);
56 if (!status
&& adjust_shared_perm(dst
))
62 int copy_file_with_time(const char *dst
, const char *src
, int mode
)
64 int status
= copy_file(dst
, src
, mode
);
66 return copy_times(dst
, src
);