[BACK]Return to crc32hash.c CVS log [TXT][DIR] Up to [Development] / linux-2.6-xfs / Documentation / pcmcia

File: [Development] / linux-2.6-xfs / Documentation / pcmcia / crc32hash.c (download)

Revision 1.1, Fri Oct 13 17:03:09 2006 UTC (11 years ago) by tes.longdrop.melbourne.sgi.com
Branch: MAIN

Merge up to 2.6.18
Merge of 2.6.x-xfs-melb:linux:27192b by kenmcd.

/* crc32hash.c - derived from linux/lib/crc32.c, GNU GPL v2 */
/* Usage example:
$ ./crc32hash "Dual Speed"
*/

#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

unsigned int crc32(unsigned char const *p, unsigned int len)
{
	int i;
	unsigned int crc = 0;
	while (len--) {
		crc ^= *p++;
		for (i = 0; i < 8; i++)
			crc = (crc >> 1) ^ ((crc & 1) ? 0xedb88320 : 0);
	}
	return crc;
}

int main(int argc, char **argv) {
	unsigned int result;
	if (argc != 2) {
		printf("no string passed as argument\n");
		return -1;
	}
	result = crc32(argv[1], strlen(argv[1]));
	printf("0x%x\n", result);
	return 0;
}