/*====================================================================*
 *
 *   uint32_t fdchecksum32 (int fd, size_t extent, uint32_t checksum);
 *
 *   memory.h
 *
 *   return the 32-bit checksum of a file region starting with the
 *   current file offset; extent specifies the number of 32-bit words;
 *
 *   the endian conversion has proven unecessary but must be kept in
 *   for the time being;
 *
 *.  Motley Tools by Charles Maier <cmaier@cmassoc.net>;
 *:  Published 2001-2006 by Charles Maier Associates Limited;
 *;  Released under the GNU General Public Licence v2 and later;
 *
 *   Contributor(s):
 *      Charles Maier <charles.maier@atheros.com>
 *	Alex Vasquez <alex.vasquez@atheros.com>
 *
 *--------------------------------------------------------------------*/

#ifndef FDCHECKSUM32_SOURCE
#define FDCHECKSUM32_SOURCE

#include <stdio.h>
#include <unistd.h>
#include <errno.h>

#include "../tools/memory.h"

uint32_t fdchecksum32 (int fd, size_t extent, uint32_t checksum) 

{
	uint32_t memory;
	while (extent-- > 0) 
	{
		if (read (fd, &memory, sizeof (memory)) < sizeof (memory)) 
		{
			return (-1);
		}
		checksum ^= LE32TOH (memory);
	}
	return (~checksum);
}

#endif