-/* $NetBSD: crc.c,v 1.5 1997/10/11 01:53:21 lukem Exp $ */
+/* $NetBSD: crc.c,v 1.11 2009/08/25 06:04:17 dholland Exp $ */
/*-
* Copyright (c) 1993
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
static char sccsid[] = "@(#)crc.c 8.1 (Berkeley) 5/31/93";
static char ORIGINAL_sccsid[] = "@(#)crc.c 5.2 (Berkeley) 4/4/91";
#else
-__RCSID("$NetBSD: crc.c,v 1.5 1997/10/11 01:53:21 lukem Exp $");
+__RCSID("$NetBSD: crc.c,v 1.11 2009/08/25 06:04:17 dholland Exp $");
#endif
#endif /* not lint */
#include "extern.h"
-unsigned long crctab[] = {
+static const unsigned long crctab[] = {
0x7fffffff,
0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e,
* it.
*/
-unsigned long crcval;
-int step;
+static unsigned long crcval;
+static unsigned int step;
void
-crc_start()
+crc_start(void)
{
crcval = step = 0;
}
+/* Process nr bytes at a time; ptr points to them */
unsigned long
-crc(ptr, nr) /* Process nr bytes at a time; ptr points to them */
- char *ptr;
- int nr;
+crc(const char *ptr, int nr)
{
int i;
- char *p;
+ const char *p;
while (nr > 0)
for (p = ptr; nr--; ++p) {
+ /*
+ * The following is not portable to machines
+ * where char is unsigned, because of sign
+ * extension. But it can't be changed without
+ * breaking save files. Sigh.
+ */
if (!(i = crcval >> 24 ^ *p)) {
i = step++;
if (step >= sizeof(crctab) / sizeof(crctab[0]))