The ndx arg passed to increment_active_files() is now the unique,
[rsync/rsync.git] / checksum.c
index ec7ec13..d4e1de9 100644 (file)
@@ -1,25 +1,28 @@
 /*
-   Copyright (C) Andrew Tridgell 1996
-   Copyright (C) Paul Mackerras 1996
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ * Routines to support checksumming of bytes.
+ *
+ * Copyright (C) 1996 Andrew Tridgell
+ * Copyright (C) 1996 Paul Mackerras
+ * Copyright (C) 2004, 2005 Wayne Davison
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
 
 #include "rsync.h"
 
-int csum_length=2; /* initial value */
+int csum_length = SHORT_SUM_LENGTH; /* initial value */
 
 #define CSUM_CHUNK 64
 
@@ -92,11 +95,11 @@ void get_checksum2(char *buf, int32 len, char *sum)
 
 void file_checksum(char *fname,char *sum,OFF_T size)
 {
-       OFF_T i;
        struct map_struct *buf;
-       int fd;
-       OFF_T len = size;
+       OFF_T i, len = size;
        struct mdfour m;
+       int32 remainder;
+       int fd;
 
        memset(sum,0,MD4_SUM_LENGTH);
 
@@ -117,8 +120,9 @@ void file_checksum(char *fname,char *sum,OFF_T size)
         * by failing to call mdfour_tail() for block sizes that
         * are multiples of 64.  This is fixed by calling mdfour_update()
         * even when there are no more bytes. */
-       if (len - i > 0 || protocol_version >= 27)
-               mdfour_update(&m, (uchar *)map_ptr(buf, i, len-i), len-i);
+       remainder = (int32)(len - i);
+       if (remainder > 0 || protocol_version >= 27)
+               mdfour_update(&m, (uchar *)map_ptr(buf, i, remainder), remainder);
 
        mdfour_result(&m, (uchar *)sum);
 
@@ -148,7 +152,7 @@ void sum_init(int seed)
  * @todo Perhaps get rid of md and just pass in the address each time.
  * Very slightly clearer and slower.
  **/
-void sum_update(char *p, int32 len)
+void sum_update(const char *p, int32 len)
 {
        if (len + sumresidue < CSUM_CHUNK) {
                memcpy(sumrbuf + sumresidue, p, len);