Blame src/crc/mdso_crc32.c

c19325
/****************************************************************/
c19325
/*  mdso: midipix dso scavenger                                 */
c19325
/*  Copyright (C) 2015  Z. Gilboa                               */
c19325
/*  Released under GPLv2 and GPLv3; see COPYING.MDSO.           */
c19325
/****************************************************************/
c19325
c19325
#include <stdint.h>
c19325
#include <unistd.h>
c19325
c19325
#include <mdso/mdso.h>
c19325
#include <mdso/mdso_crc32.h>
c19325
c19325
static const uint32_t crc32_table[256] = MDSO_CRC32_TABLE;
c19325
c19325
uint32_t mdso_crc32_mbstr(const unsigned char * str, size_t * symlen)
c19325
{
c19325
	const unsigned char *	ch;
c19325
	uint32_t		crc32;
c19325
c19325
	crc32	= 0 ^ 0xFFFFFFFF;
c19325
	ch	= str;
c19325
c19325
	while (*ch) {
c19325
		crc32 = (crc32 >> 8) ^ crc32_table[(crc32 ^ *ch) & 0xFF];
c19325
		ch++;
c19325
	}
c19325
c19325
	if (symlen)
c19325
		*symlen = ch - str;
c19325
c19325
	return (crc32 ^ 0xFFFFFFFF);
c19325
}