1: #ifndef lint
   2: static char sccsid[] = "@(#)chksum.c	4.2 (Berkeley) 6/19/85";
   3: #endif
   4: 
   5: #ifndef pdp11
   6: chksum (s, n)
   7: register char *s;
   8: register n;
   9: {
  10:     register long sum, x, t;
  11: 
  12:     sum = 0xffff;
  13:     x = 0;
  14:     do {
  15:         /* Rotate left, copying bit 15 to bit 0 */
  16:         sum <<= 1;
  17:         if (sum & 0x10000)
  18:             sum ^= 0x10001;
  19:         t = sum;
  20:         sum = (sum + (*s++ & 0377)) & 0xffff;
  21:         x += sum ^ n;
  22:         if (sum <= t)
  23:             sum = (sum ^ x) & 0xffff;
  24:     } while (--n > 0);
  25: 
  26:     return (long) (short) sum;
  27: }
  28: #else pdp11
  29: chksum(s,n)
  30: register char *s;
  31: register n;
  32: {
  33:     register unsigned sum, t;
  34:     register x;
  35: 
  36:     sum = -1;
  37:     x = 0;
  38: 
  39:     do {
  40:         if (sum&0x8000) {
  41:             sum <<= 1;
  42:             sum++;
  43:         } else
  44:             sum <<= 1;
  45:         t = sum;
  46:         sum += (unsigned)*s++ & 0377;
  47:         x += sum^n;
  48:         if ((sum&0xffff) <= (t&0xffff)) {
  49:             sum ^= x;
  50:         }
  51:     } while (--n > 0);
  52: 
  53:     return sum & 0xffff;
  54: }
  55: 
  56: #endif pdp11

Defined functions

chksum defined in line 29; used 2 times

Defined variables

sccsid defined in line 2; never used
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1706
Valid CSS Valid XHTML 1.0 Strict