3 int copy_fd(int ifd
, int ofd
)
8 ssize_t len
= xread(ifd
, buffer
, sizeof(buffer
));
15 return error("copy-fd: read returned %s",
16 strerror(read_error
));
19 int written
= xwrite(ofd
, buf
, len
);
26 return error("copy-fd: write returned 0");
29 return error("copy-fd: write returned %s",
38 int copy_file(const char *dst
, const char *src
, int mode
)
42 mode
= (mode
& 0111) ? 0777 : 0666;
43 if ((fdi
= open(src
, O_RDONLY
)) < 0)
45 if ((fdo
= open(dst
, O_WRONLY
| O_CREAT
| O_EXCL
, mode
)) < 0) {
49 status
= copy_fd(fdi
, fdo
);
51 return error("%s: write error: %s", dst
, strerror(errno
));
53 if (!status
&& adjust_shared_perm(dst
))