summaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/util.c b/src/util.c
index 18f8fa4..ffc5dc3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -18,8 +18,6 @@
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***/
-#define USE_SENDFILE
-
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
@@ -230,15 +228,20 @@ int copy_fd(int sfd, int dfd, off_t l) {
static size_t psize = 0;
#ifdef USE_SENDFILE
- if (!copy_fd_sendfile(sfd, dfd, l))
+ if (copy_fd_sendfile(sfd, dfd, l) == 0)
return 0;
+
+ if (errno == ENOSPC)
+ return -1;
#endif
//fprintf(stderr, "copy_fd(%u)\n", l);
if (psize == 0)
- psize = sysconf(_SC_PAGESIZE);
+ psize = (off_t) sysconf(_SC_PAGESIZE);
+ assert(psize > 0);
+
sp = dp = MAP_FAILED;
if (l > BUFSIZE) {
@@ -346,10 +349,8 @@ int copy_fd(int sfd, int dfd, off_t l) {
fprintf(stderr, "mmap(): %s\n", strerror(errno));
return -1;
}
-
}
-
} else if (dp == MAP_FAILED) { /* copy mmap to fd */
for (;;) {
@@ -386,7 +387,6 @@ int copy_fd(int sfd, int dfd, off_t l) {
}
}
-
} else { /* copy mmap to mmap */
for (;;) {
@@ -421,6 +421,7 @@ int copy_fd(int sfd, int dfd, off_t l) {
mdfo = (dfo/psize)*psize;
dm = m+(dfo-mdfo);
if ((dp = mmap(NULL, dm, PROT_READ|PROT_WRITE, MAP_SHARED, dfd, mdfo)) == MAP_FAILED) {
+ munmap(sp, sm);
fprintf(stderr, "mmap(): %s\n", strerror(errno));
return -1;
}
@@ -640,7 +641,6 @@ int question(const char *text, const char *replies) {
}
}
-
finish:
fputc('\r', stderr);
@@ -649,7 +649,6 @@ finish:
fclose(f);
return r;
-
}