xref: /original-bsd/lib/libc/string/memcmp.c (revision cf2124ff)
1 /*-
2  * Copyright (c) 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Chris Torek.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #if defined(LIBC_SCCS) && !defined(lint)
12 static char sccsid[] = "@(#)memcmp.c	5.6 (Berkeley) 01/26/91";
13 #endif /* LIBC_SCCS and not lint */
14 
15 #include <sys/cdefs.h>
16 #include <string.h>
17 
18 /*
19  * Compare memory regions.
20  */
21 int
22 memcmp(s1, s2, n)
23 	const void *s1, *s2;
24 	size_t n;
25 {
26 	if (n != 0) {
27 		register const unsigned char *p1 = s1, *p2 = s2;
28 
29 		do {
30 			if (*p1++ != *p2++)
31 				return (*--p1 - *--p2);
32 		} while (--n != 0);
33 	}
34 	return (0);
35 }
36