diff --git a/src/fs_clonefile.cpp b/src/fs_clonefile.cpp index 68c014f8..0c3ceb7c 100644 --- a/src/fs_clonefile.cpp +++ b/src/fs_clonefile.cpp @@ -57,19 +57,18 @@ writen(const int fd, ssize_t nwritten; nleft = count; - while(nleft > 0) + do { nwritten = fs::write(fd,buf,nleft); + if((nwritten == -1) && (errno == EINTR)) + continue; if(nwritten == -1) - { - if(errno == EINTR) - continue; - return -1; - } + return -1; nleft -= nwritten; buf += nwritten; } + while(nleft > 0); return count; } @@ -96,12 +95,12 @@ copyfile_rw(const int fdin, while(totalwritten < count) { nr = fs::read(fdin,&buf[0],bufsize); + if(nr == 0) + return totalwritten; + if((nr == -1) && (errno == EINTR)) + continue; if(nr == -1) - { - if(errno == EINTR) - continue; - return -1; - } + return -1; nw = writen(fdout,&buf[0],nr); if(nw == -1) @@ -110,7 +109,7 @@ copyfile_rw(const int fdin, totalwritten += nw; } - return count; + return totalwritten; } static