-/* 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.
#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
} ;
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;
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 );
#ifdef MAKETAB
#include <stdio.h>
-main()
+int main(void)
{
initcrctab();
}
-initcrctab()
+void initcrctab(void)
{
register int b, i;
WTYPE v;
printf(" ");
}
}
-#endif
+#endif /* MAKETAB */
#ifdef TEST
-main( ac, av )
- int ac; char **av;
+main( int ac, char **av)
{
int fd;
int nr;
/* 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 */