xref: /csrg-svn/sys/ufs/lfs/lfs_cksum.c (revision 51185)
1*51185Sbostic /*-
2*51185Sbostic  * Copyright (c) 1991 The Regents of the University of California.
3*51185Sbostic  * All rights reserved.
4*51185Sbostic  *
5*51185Sbostic  * %sccs.include.redist.c%
6*51185Sbostic  *
7*51185Sbostic  *	@(#)lfs_cksum.c	5.1 (Berkeley) 09/25/91
8*51185Sbostic  */
9*51185Sbostic 
10*51185Sbostic #include <sys/types.h>
11*51185Sbostic 
12*51185Sbostic /*
13*51185Sbostic  * cksum --
14*51185Sbostic  *	Simple, general purpose, fast checksum.
15*51185Sbostic  */
16*51185Sbostic u_long
17*51185Sbostic cksum(str, len)
18*51185Sbostic 	register void *str;
19*51185Sbostic 	register size_t len;
20*51185Sbostic {
21*51185Sbostic 	register u_long sum;
22*51185Sbostic 
23*51185Sbostic 	len &= ~(sizeof(u_short) - 1);
24*51185Sbostic 	for (sum = 0; len; len -= sizeof(u_short))
25*51185Sbostic 		sum ^= *((u_short *)str)++;
26*51185Sbostic 	return (sum);
27*51185Sbostic }
28