diff --git a/bin/cp/utils.c b/bin/cp/utils.c --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -104,7 +104,7 @@ struct stat sb, *fs; ssize_t wcount; 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; fs = entp->fts_statp; @@ -216,15 +216,18 @@ if (!use_copy_file_range) { wcount = copy_fallback(from_fd, to_fd); } - wtotal += wcount; + if (wcount >= 0) + wtotal += wcount; if (info) { info = 0; + serrno = errno; (void)fprintf(stderr, "%s -> %s%s %3d%%\n", entp->fts_path, to.base, to.path, cp_pct(wtotal, fs->st_size)); + errno = serrno; } - } while (wcount > 0); + } while (wcount > 0 || (wcount < 0 && errno == EINTR)); if (wcount < 0) { warn("%s", entp->fts_path); rval = 1;