diff options
author | Andrew Tridgell <tridge@samba.org> | 1996-06-30 04:29:46 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1996-06-30 04:29:46 +0000 |
commit | aae43eb38f8c49c8ac675f8269b06d11a72bd10e (patch) | |
tree | d3970e5058d47dfa392aed5fc35ca7c3de7f3a2d /checksum.c | |
parent | dc5ddbccace1f4f37d57ce5d961117effc28a356 (diff) | |
download | rsync-aae43eb38f8c49c8ac675f8269b06d11a72bd10e.tar.gz |
added checksum seed
Diffstat (limited to 'checksum.c')
-rw-r--r-- | checksum.c | 28 |
1 files changed, 19 insertions, 9 deletions
@@ -23,8 +23,7 @@ int csum_length=SUM_LENGTH; #define CSUM_CHUNK 64 -static char *tmpchunk = NULL; - +int checksum_seed = 0; /* a simple 32 bit checksum that can be upadted from either end @@ -63,16 +62,28 @@ void get_checksum2(char *buf,int len,char *sum) { int i; MDstruct MD; + static char *buf1 = NULL; + static int len1 = 0; + + if (len > len1) { + if (buf1) free(buf1); + buf1 = (char *)malloc(len+sizeof(checksum_seed)); + len1 = len; + if (!buf1) out_of_memory("get_checksum2"); + } MDbegin(&MD); - for(i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) { - bcopy(buf+i,tmpchunk,CSUM_CHUNK); - MDupdate(&MD, tmpchunk, CSUM_CHUNK*8); + bcopy(buf,buf1,len); + if (checksum_seed) { + bcopy((char *)&checksum_seed,buf1+len,sizeof(checksum_seed)); + len += sizeof(checksum_seed); } - bcopy(buf+i,tmpchunk,len-i); - MDupdate(&MD, tmpchunk, (len-i)*8); + for(i = 0; i + CSUM_CHUNK <= len; i += CSUM_CHUNK) { + MDupdate(&MD, buf1+i, CSUM_CHUNK*8); + } + MDupdate(&MD, buf1+i, (len-i)*8); sum_put(&MD,sum); } @@ -85,6 +96,7 @@ void file_checksum(char *fname,char *sum,off_t size) char *buf; int fd; int len = size; + char tmpchunk[CSUM_CHUNK]; bzero(sum,csum_length); @@ -112,8 +124,6 @@ void file_checksum(char *fname,char *sum,off_t size) void checksum_init(void) { - tmpchunk = (char *)malloc(CSUM_CHUNK); - if (!tmpchunk) out_of_memory("checksum_init"); } |