xref: /freebsd/contrib/unbound/compat/memcmp.c (revision 40f65a4df509c6b29b9e72407c7afefe28838844)
1*b7579f77SDag-Erling Smørgrav /*
2*b7579f77SDag-Erling Smørgrav  *	memcmp.c: memcmp compat implementation.
3*b7579f77SDag-Erling Smørgrav  *
4*b7579f77SDag-Erling Smørgrav  *	Copyright (c) 2010, NLnet Labs. All rights reserved.
5*b7579f77SDag-Erling Smørgrav  *
6*b7579f77SDag-Erling Smørgrav  * See LICENSE for the license.
7*b7579f77SDag-Erling Smørgrav */
8*b7579f77SDag-Erling Smørgrav 
9*b7579f77SDag-Erling Smørgrav #include <config.h>
10*b7579f77SDag-Erling Smørgrav 
11*b7579f77SDag-Erling Smørgrav int memcmp(const void *x, const void *y, size_t n);
12*b7579f77SDag-Erling Smørgrav 
memcmp(const void * x,const void * y,size_t n)13*b7579f77SDag-Erling Smørgrav int memcmp(const void *x, const void *y, size_t n)
14*b7579f77SDag-Erling Smørgrav {
15*b7579f77SDag-Erling Smørgrav 	const uint8_t* x8 = (const uint8_t*)x;
16*b7579f77SDag-Erling Smørgrav 	const uint8_t* y8 = (const uint8_t*)y;
17*b7579f77SDag-Erling Smørgrav 	size_t i;
18*b7579f77SDag-Erling Smørgrav 	for(i=0; i<n; i++) {
19*b7579f77SDag-Erling Smørgrav 		if(x8[i] < y8[i])
20*b7579f77SDag-Erling Smørgrav 			return -1;
21*b7579f77SDag-Erling Smørgrav 		else if(x8[i] > y8[i])
22*b7579f77SDag-Erling Smørgrav 			return 1;
23*b7579f77SDag-Erling Smørgrav 	}
24*b7579f77SDag-Erling Smørgrav 	return 0;
25*b7579f77SDag-Erling Smørgrav }
26