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