]> arthur.barton.de Git - netatalk.git/blobdiff - bin/megatron/updcrc.c
Merge remote branch 'sf/branch-allea' into branch-allea
[netatalk.git] / bin / megatron / updcrc.c
index 37ad7aff8b20d92c97c8f4972f15df21849d72e6..d327571dc20d6cc41f9ca215082564403da036ae 100644 (file)
@@ -1,4 +1,7 @@
-/* updcrc(3), crc(1) - calculate crc polynomials
+/*
+ * $Id: updcrc.c,v 1.5 2009-10-13 22:55:36 didg Exp $
+ *
+ * updcrc(3), crc(1) - calculate crc polynomials
  *
  * Calculate, intelligently, the CRC of a dataset incrementally given a 
  * buffer full at a time.
@@ -27,7 +30,9 @@
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
+#endif /* HAVE_CONFIG_H */
+
+#include "updcrc.h"
 
 /* The CRC polynomial.
  * These 4 values define the crc-polynomial.
     /* Value used by:                  CCITT   XMODEM  ARC     */
 #define        P        0x1021 /* the poly:    0x1021  0x1021  A001    */
 #define INIT_CRC 0L    /* init value:  -1      0       0       */
-/*#define SWAPPED      /* bit order:   undef   defined defined */
-#define W      16      /* bits in CRC:16       16      16      */
-
-    /* data type that holds a W-bit unsigned integer */
-#if W <= 16
-#  define WTYPE        unsigned short
-#else
-#  define WTYPE   u_int32_t
-#endif
-
+#if 0
+#define SWAPPED        /* bit order:   undef   defined defined */
+#endif /* 0 */
     /* the number of bits per char: don't change it. */
 #define B      8
 
@@ -86,10 +84,7 @@ static WTYPE crctab[1<<B] = /* as calculated by initcrctab() */ {
 } ;
 
 WTYPE
-updcrc( icrc, icp, icnt )
-    WTYPE icrc;
-    unsigned char *icp;
-    int icnt;
+updcrc(WTYPE icrc, unsigned char *icp, int icnt)
 {
     register WTYPE crc = icrc;
     register unsigned char *cp = icp;
@@ -98,9 +93,9 @@ updcrc( icrc, icp, icnt )
     while( cnt-- ) {
 #ifndef SWAPPED
        crc = (crc<<B) ^ crctab[(crc>>(W-B)) ^ *cp++];
-#else
+#else /* SWAPPED */
        crc = (crc>>B) ^ crctab[(crc & ((1<<B)-1)) ^ *cp++]; 
-#endif SWAPPED
+#endif /* SWAPPED */
     }
 
     return( crc );
@@ -109,12 +104,12 @@ updcrc( icrc, icp, icnt )
 #ifdef MAKETAB
 
 #include <stdio.h>
-main()
+int main(void)
 {
     initcrctab();
 }
 
-initcrctab()
+void initcrctab(void)
 {
     register  int b, i;
     WTYPE v;
@@ -137,7 +132,7 @@ initcrctab()
            printf("  ");
     }
 }
-#endif
+#endif /* MAKETAB */
 
 #ifdef TEST
 
@@ -148,8 +143,7 @@ initcrctab()
 
 
 
-main( ac, av )
-    int ac; char **av;
+main( int ac, char **av)
 {
     int fd;
     int nr;
@@ -189,7 +183,7 @@ main( ac, av )
     /* crc should now equal magic */
     buf[0] = buf[1] = buf[2] = buf[3] = 0;
     printf( "magic test: %lx =?= %lx\n", crc, updcrc(-1, buf, W/B));
-#endif MAGICCHECK
+#endif /* MAGICCHECK */
 }
 
-#endif
+#endif /* TEST */