OSDN Git Service

pgindent run.
[pg-rex/syncrep.git] / src / port / memcmp.c
1 /*-------------------------------------------------------------------------
2  *
3  * memcmp.c
4  *        compares memory bytes
5  *
6  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  *        $Header: /cvsroot/pgsql/src/port/memcmp.c,v 1.2 2002/09/04 20:31:48 momjian Exp $
12  *
13  * This file was taken from NetBSD and is used by SunOS because memcmp
14  * on that platform does not properly compare negative bytes.
15  *
16  *-------------------------------------------------------------------------
17  */
18
19 #include <string.h>
20
21 /*
22  * Compare memory regions.
23  */
24 int
25 memcmp(const void *s1, const void *s2, size_t n)
26 {
27         if (n != 0)
28         {
29                 const unsigned char *p1 = s1,
30                                    *p2 = s2;
31
32                 do
33                 {
34                         if (*p1++ != *p2++)
35                                 return (*--p1 - *--p2);
36                 } while (--n != 0);
37         }
38         return 0;
39 }