Changeset View
Changeset View
Standalone View
Standalone View
bin/cp/utils.c
| Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| int | int | ||||
| copy_file(const FTSENT *entp, bool dne, bool beneath) | copy_file(const FTSENT *entp, bool dne, bool beneath) | ||||
| { | { | ||||
| struct stat sb, *fs; | struct stat sb, *fs; | ||||
| ssize_t wcount; | ssize_t wcount; | ||||
| off_t wtotal; | off_t wtotal; | ||||
| int ch, checkch, from_fd, rval, to_fd; | int ch, checkch, from_fd, rval, serrno, to_fd; | ||||
| bool use_copy_file_range = true; | bool use_copy_file_range = true; | ||||
| fs = entp->fts_statp; | fs = entp->fts_statp; | ||||
| from_fd = to_fd = -1; | from_fd = to_fd = -1; | ||||
| if (!lflag && !sflag) { | if (!lflag && !sflag) { | ||||
| if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) < 0 || | if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) < 0 || | ||||
| fstat(from_fd, &sb) != 0) { | fstat(from_fd, &sb) != 0) { | ||||
| warn("%s", entp->fts_path); | warn("%s", entp->fts_path); | ||||
| ▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | if (use_copy_file_range) { | ||||
| if (wcount < 0 && errno == EINVAL) { | if (wcount < 0 && errno == EINVAL) { | ||||
| /* probably a non-seekable descriptor */ | /* probably a non-seekable descriptor */ | ||||
| use_copy_file_range = false; | use_copy_file_range = false; | ||||
| } | } | ||||
| } | } | ||||
| if (!use_copy_file_range) { | if (!use_copy_file_range) { | ||||
| wcount = copy_fallback(from_fd, to_fd); | wcount = copy_fallback(from_fd, to_fd); | ||||
| } | } | ||||
| if (wcount >= 0) | |||||
| wtotal += wcount; | wtotal += wcount; | ||||
| if (info) { | if (info) { | ||||
| info = 0; | info = 0; | ||||
| serrno = errno; | |||||
| (void)fprintf(stderr, | (void)fprintf(stderr, | ||||
| "%s -> %s%s %3d%%\n", | "%s -> %s%s %3d%%\n", | ||||
| entp->fts_path, to.base, to.path, | entp->fts_path, to.base, to.path, | ||||
| cp_pct(wtotal, fs->st_size)); | cp_pct(wtotal, fs->st_size)); | ||||
| errno = serrno; | |||||
| } | } | ||||
| } while (wcount > 0); | } while (wcount > 0 || (wcount < 0 && errno == EINTR)); | ||||
| if (wcount < 0) { | if (wcount < 0) { | ||||
| warn("%s", entp->fts_path); | warn("%s", entp->fts_path); | ||||
| rval = 1; | rval = 1; | ||||
| } | } | ||||
| /* | /* | ||||
| * Don't remove the target even after an error. The target might | * Don't remove the target even after an error. The target might | ||||
| * not be a regular file, or its attributes might be important, | * not be a regular file, or its attributes might be important, | ||||
| ▲ Show 20 Lines • Show All 258 Lines • Show Last 20 Lines | |||||