xref: /csrg-svn/sys/ufs/lfs/lfs_cksum.c (revision 51215)
151185Sbostic /*-
251185Sbostic  * Copyright (c) 1991 The Regents of the University of California.
351185Sbostic  * All rights reserved.
451185Sbostic  *
551185Sbostic  * %sccs.include.redist.c%
651185Sbostic  *
7*51215Sbostic  *	@(#)lfs_cksum.c	5.2 (Berkeley) 10/02/91
851185Sbostic  */
951185Sbostic 
10*51215Sbostic #ifdef LOGFS
1151185Sbostic #include <sys/types.h>
1251185Sbostic 
1351185Sbostic /*
14*51215Sbostic  * Simple, general purpose, fast checksum.  Data must be short-aligned.
15*51215Sbostic  * Returns a u_long in case we ever want to do something more rigorous.
1651185Sbostic  */
1751185Sbostic u_long
1851185Sbostic cksum(str, len)
1951185Sbostic 	register void *str;
2051185Sbostic 	register size_t len;
2151185Sbostic {
2251185Sbostic 	register u_long sum;
2351185Sbostic 
2451185Sbostic 	len &= ~(sizeof(u_short) - 1);
2551185Sbostic 	for (sum = 0; len; len -= sizeof(u_short))
2651185Sbostic 		sum ^= *((u_short *)str)++;
2751185Sbostic 	return (sum);
2851185Sbostic }
29*51215Sbostic #endif /* LOGFS */
30