xref: /netbsd-src/external/bsd/openldap/dist/libraries/liblutil/memcmp.c (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1 /*	$NetBSD: memcmp.c,v 1.1.1.2 2010/03/08 02:14:20 lukem Exp $	*/
2 
3 /* OpenLDAP: pkg/ldap/libraries/liblutil/memcmp.c,v 1.9.2.4 2009/01/22 00:00:58 kurt Exp */
4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5  *
6  * Copyright 1998-2009 The OpenLDAP Foundation.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in the file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 
18 #include "portable.h"
19 
20 #include <ac/string.h>
21 
22 /*
23  * Memory Compare
24  */
25 int
26 (lutil_memcmp)(const void *v1, const void *v2, size_t n)
27 {
28     if (n != 0) {
29 		const unsigned char *s1=v1, *s2=v2;
30         do {
31             if (*s1++ != *s2++) return *--s1 - *--s2;
32         } while (--n != 0);
33     }
34     return 0;
35 }
36