Changeset View
Changeset View
Standalone View
Standalone View
bin/cp/utils.c
| Show First 20 Lines • Show All 99 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, to_fd; | ||||
| int use_copy_file_range = 1; | 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); | ||||
| if (from_fd >= 0) | if (from_fd >= 0) | ||||
| ▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | copy_file(const FTSENT *entp, bool dne, bool beneath) | ||||
| wtotal = 0; | wtotal = 0; | ||||
| do { | do { | ||||
| if (use_copy_file_range) { | if (use_copy_file_range) { | ||||
| wcount = copy_file_range(from_fd, NULL, | wcount = copy_file_range(from_fd, NULL, | ||||
| to_fd, NULL, SSIZE_MAX, 0); | to_fd, NULL, SSIZE_MAX, 0); | ||||
| if (wcount < 0 && errno == EINVAL) { | if (wcount < 0 && errno == EINVAL) { | ||||
| /* probably a non-seekable descriptor */ | /* probably a non-seekable descriptor */ | ||||
| use_copy_file_range = 0; | 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); | ||||
| } | } | ||||
| wtotal += wcount; | wtotal += wcount; | ||||
| if (info) { | if (info) { | ||||
| info = 0; | info = 0; | ||||
| ▲ Show 20 Lines • Show All 272 Lines • Show Last 20 Lines | |||||