1 /* memcmp.c -- Replacement memcmp.c
2 *
3 * Useful on systems that don't have a working memcmp, such as SunOS
4 * 4.1.3 and NeXT x86 OpenStep.
5 *
6 * Copyright (C) 2002 - 2003 Matthias Andree <matthias.andree@gmx.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program (see the file COPYING included with this
20 * distribution); if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include <string.h>
25
memcmp(const void * s1,const void * s2,size_t n)26 int memcmp(const void *s1, const void *s2, size_t n)
27 {
28 register unsigned const char *p1 = s1, *p2 = s2;
29 int d;
30
31 while (n-- > 0) {
32 d = *p1++ - *p2++;
33 if (d != 0)
34 return d;
35 }
36 return 0;
37 }
38