From 17fac7f2c92df794b88648a95bea6796621dbe83 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 7 Sep 2003 23:11:37 +0000 Subject: Many fixes, primarily documentation git-svn-id: file:///home/lennart/svn/public/syrep/trunk@32 07ea20a6-d2c5-0310-9e02-9ef735347d72 --- src/util.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/util.c') 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 #include #include @@ -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; - } -- cgit