151185Sbostic /*- 251185Sbostic * Copyright (c) 1991 The Regents of the University of California. 351185Sbostic * All rights reserved. 451185Sbostic * 551185Sbostic * %sccs.include.redist.c% 651185Sbostic * 7*51487Sbostic * @(#)lfs_cksum.c 5.3 (Berkeley) 11/01/91 851185Sbostic */ 951185Sbostic 10*51487Sbostic #include <sys/param.h> 1151185Sbostic 12*51487Sbostic #include <lfs/lfs.h> 13*51487Sbostic #include <lfs/lfs_extern.h> 14*51487Sbostic 1551185Sbostic /* 1651215Sbostic * Simple, general purpose, fast checksum. Data must be short-aligned. 1751215Sbostic * Returns a u_long in case we ever want to do something more rigorous. 18*51487Sbostic * 19*51487Sbostic * XXX 20*51487Sbostic * Use the TCP/IP checksum instead. 2151185Sbostic */ 2251185Sbostic u_long 2351185Sbostic cksum(str, len) 2451185Sbostic register void *str; 2551185Sbostic register size_t len; 2651185Sbostic { 2751185Sbostic register u_long sum; 2851185Sbostic 2951185Sbostic len &= ~(sizeof(u_short) - 1); 3051185Sbostic for (sum = 0; len; len -= sizeof(u_short)) 3151185Sbostic sum ^= *((u_short *)str)++; 3251185Sbostic return (sum); 3351185Sbostic } 34