+ copy_dir();
+ }
+ /* Preserve old times/modes if necessary. */
+ if (preserve_flag)
+ (void)chmod(to.p_path, (int) from_stat.st_mode);
+ else if (new_target_dir)
+ (void)chmod(to.p_path, (int) from_stat.st_mode & ~my_umask);
+ if (preserve_flag || new_target_dir) {
+ static struct timeval tv[2];
+
+ tv[0].tv_sec = from_stat.st_atime;
+ tv[1].tv_sec = from_stat.st_mtime;
+ if (utimes(to.p_path, tv))
+ error(to.p_path);
+ }
+}
+
+copy_file(mode)
+ u_short mode; /* Permissions for new file. */
+{
+ int from_fd, to_fd, rcount, wcount;
+
+ from_fd = open(from.p_path, O_RDONLY, 0);
+ if (from_fd == -1) {
+ error(from.p_path);
+ (void)close(from_fd);
+ return(0);
+ }
+
+ /*
+ * In the interactive case, use O_EXCL to notice existing files. If
+ * the file exists, verify with the user.
+ */
+ to_fd = open(to.p_path,
+ (interactive_flag ? O_EXCL : 0) | O_WRONLY | O_CREAT | O_TRUNC,
+ mode);
+
+ if (to_fd == -1 && errno == EEXIST && interactive_flag) {
+ int checkch, ch;
+
+ (void)fprintf(stderr, "overwrite %s? ", to.p_path);
+ checkch = ch = getchar();
+ while (ch != '\n' && ch != EOF)
+ ch = getchar();
+ if (checkch != 'y')
+ return(0);
+ /* try again. */
+ to_fd = open(to.p_path, O_WRONLY | O_CREAT | O_TRUNC, mode);