summaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/util.c b/src/util.c
index 5040259..a7118ac 100644
--- a/src/util.c
+++ b/src/util.c
@@ -95,6 +95,9 @@ void rotdash(void) {
static const char dashes[] = /* ".oOo"; */ "|/-\\";
const static char *d = dashes;
+ if (!args.progress_flag)
+ return;
+
if (stderr_tty < 0)
stderr_tty = isatty(fileno(stderr));
@@ -108,6 +111,9 @@ void rotdash(void) {
}
void rotdash_hide(void) {
+ if (!args.progress_flag)
+ return;
+
if (stderr_tty < 0)
stderr_tty = isatty(fileno(stderr));
@@ -156,24 +162,32 @@ int isdirectory(const char *path) {
#ifdef USE_SENDFILE
-static int copy_fd_sendfile(int sfd, int dfd, size_t l) {
+#define MAX_SENDFILE_SIZE (1024*1024*1024) /* A gigabyte */
+
+static int copy_fd_sendfile(int sfd, int dfd, off_t l) {
off_t sfo, o;
- ssize_t r;
if ((sfo = lseek(sfd, 0, SEEK_CUR)) == (off_t) -1)
o = 0;
else
o = sfo;
-
- if ((r = sendfile(dfd, sfd, &o, l)) != l)
- return -1;
- if (sfo != (off_t) -1) {
- sfo += r;
+ while (l > 0) {
+ size_t m = l > MAX_SENDFILE_SIZE ? MAX_SENDFILE_SIZE : l;
+ ssize_t r;
+
+ if ((r = sendfile(dfd, sfd, &o, m)) <= 0)
+ return -1;
+
+ l -= r;
- lseek(sfd, sfo, SEEK_SET);
+ if (sfo != (off_t) -1)
+ sfo += r;
}
+ if (sfo != (off_t) -1)
+ lseek(sfd, sfo, SEEK_SET);
+
return 0;
}
@@ -185,7 +199,7 @@ off_t filesize(int fd) {
if (fstat(fd, &st) < 0) {
fprintf(stderr, "stat(): %s\n", strerror(errno));
- return -1;
+ return (off_t) -1;
}
return st.st_size;
@@ -206,7 +220,7 @@ int expand_file(int fd, off_t l) {
return 0;
}
-#define MMAPSIZE (100*1024*1024)
+#define MMAPSIZE (100*1024*1024) /* 100MB */
#define BUFSIZE (32*1024)
int copy_fd(int sfd, int dfd, off_t l) {
@@ -229,7 +243,7 @@ int copy_fd(int sfd, int dfd, off_t l) {
if (l > BUFSIZE) {
- m = l < MMAPSIZE ? l : MMAPSIZE;
+ m = (size_t) (l < MMAPSIZE ? l : MMAPSIZE);
if ((sfo = lseek(sfd, 0, SEEK_CUR)) != (off_t) -1) {
off_t s;
@@ -238,7 +252,7 @@ int copy_fd(int sfd, int dfd, off_t l) {
return -1;
if (s < sfo+l) {
- fprintf(stderr, "File too short (%u vs. %lu %i)\n", s, sfo+l, l);
+ fprintf(stderr, "File too short\n");
return -1;
}
@@ -268,8 +282,7 @@ int copy_fd(int sfd, int dfd, off_t l) {
while (l > 0) {
off_t n;
-
- m = l > BUFSIZE ? BUFSIZE : l;
+ size_t m = l > BUFSIZE ? BUFSIZE : l;
if ((n = loop_read(sfd, buf, m)) != m) {
@@ -417,7 +430,7 @@ int copy_fd(int sfd, int dfd, off_t l) {
int copy_file(const char *src, const char *dst, int c) {
int sfd = -1, dfd = -1, r = -1;
- size_t size;
+ off_t size;
if ((sfd = open(src, O_RDONLY)) < 0) {
fprintf(stderr, "open(\"%s\", O_RDONLY): %s\n", src, strerror(errno));