]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - adventure/crc.c
NULL does not need a cast
[bsdgames-darwin.git] / adventure / crc.c
index 768882d9aa8e14bf9771b523f96eda736f4c6ba8..d429e91298dfb20e02ebe47954898454180c711b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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,
@@ -110,25 +106,30 @@ unsigned long crctab[] = {
  *      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]))