3 int copy_fd(int ifd
, int ofd
)
7 ssize_t len
= xread(ifd
, buffer
, sizeof(buffer
));
11 return COPY_READ_ERROR
;
12 if (write_in_full(ofd
, buffer
, len
) < 0)
13 return COPY_WRITE_ERROR
;
18 static int copy_times(const char *dst
, const char *src
)
22 if (stat(src
, &st
) < 0)
24 times
.actime
= st
.st_atime
;
25 times
.modtime
= st
.st_mtime
;
26 if (utime(dst
, ×
) < 0)
31 int copy_file(const char *dst
, const char *src
, int mode
)
35 mode
= (mode
& 0111) ? 0777 : 0666;
36 if ((fdi
= open(src
, O_RDONLY
)) < 0)
38 if ((fdo
= open(dst
, O_WRONLY
| O_CREAT
| O_EXCL
, mode
)) < 0) {
42 status
= copy_fd(fdi
, fdo
);
45 error("copy-fd: read returned %s", strerror(errno
));
47 case COPY_WRITE_ERROR
:
48 error("copy-fd: write returned %s", strerror(errno
));
53 return error("%s: close error: %s", dst
, strerror(errno
));
55 if (!status
&& adjust_shared_perm(dst
))
61 int copy_file_with_time(const char *dst
, const char *src
, int mode
)
63 int status
= copy_file(dst
, src
, mode
);
65 return copy_times(dst
, src
);