3 int copy_fd(int ifd
, int ofd
)
8 ssize_t len
= xread(ifd
, buffer
, sizeof(buffer
));
12 int read_error
= errno
;
14 return error("copy-fd: read returned %s",
15 strerror(read_error
));
18 int written
= xwrite(ofd
, buf
, len
);
25 return error("copy-fd: write returned 0");
27 int write_error
= errno
;
29 return error("copy-fd: write returned %s",
30 strerror(write_error
));
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: close error: %s", dst
, strerror(errno
));
53 if (!status
&& adjust_shared_perm(dst
))