X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/575f2fca9ab74cb30cca67323a414d7b0cdd0845..73233f0f1232c337ede5fae3f9f95d78457df7d0:/io.c diff --git a/io.c b/io.c index 1b2fb221..4e43d33c 100644 --- a/io.c +++ b/io.c @@ -187,7 +187,7 @@ int64 read_longint(int f) if (ret != -1) return ret; -#ifndef HAVE_LONGLONG +#ifdef NO_INT64 fprintf(FERROR,"Integer overflow - attempted 64 bit offset\n"); exit_cleanup(1); #else @@ -237,45 +237,66 @@ static int last_sparse; int sparse_end(int f) { - if (last_sparse) { - lseek(f,-1,SEEK_CUR); - return (write(f,&last_byte,1) == 1 ? 0 : -1); - } - last_sparse = 0; - return 0; + if (last_sparse) { + do_lseek(f,-1,SEEK_CUR); + return (write(f,&last_byte,1) == 1 ? 0 : -1); + } + last_sparse = 0; + return 0; } -int write_sparse(int f,char *buf,int len) + +static int write_sparse(int f,char *buf,int len) { - int l1=0,l2=0; - int ret; + int l1=0,l2=0; + int ret; - if (!sparse_files) - return write(f,buf,len); + for (l1=0;l1 0) + last_sparse=1; - if (l1 == len || l2 > 0) - last_sparse=1; + if (l1 > 0) + do_lseek(f,l1,SEEK_CUR); - if (l1 > 0) - lseek(f,l1,SEEK_CUR); + if (l1 == len) + return len; - if (l1 == len) - return len; + if ((ret=write(f,buf+l1,len-(l1+l2))) != len-(l1+l2)) { + if (ret == -1 || ret == 0) return ret; + return (l1+ret); + } - if ((ret=write(f,buf+l1,len-(l1+l2))) != len-(l1+l2)) { - if (ret == -1 || ret == 0) return ret; - return (l1+ret); - } + if (l2 > 0) + do_lseek(f,l2,SEEK_CUR); + + return len; +} + + + +int write_file(int f,char *buf,int len) +{ + int ret = 0; - if (l2 > 0) - lseek(f,l2,SEEK_CUR); + if (!sparse_files) + return write(f,buf,len); - return len; + while (len>0) { + int len1 = MIN(len, SPARSE_WRITE_SIZE); + int r1 = write_sparse(f, buf, len1); + if (r1 <= 0) { + if (ret > 0) return ret; + return r1; + } + len -= r1; + buf += r1; + ret += r1; + } + return ret; }