]> granicus.if.org Git - postgresql/blob - src/port/memcmp.c
Update copyrights in source tree to 2008.
[postgresql] / src / port / memcmp.c
1 /*-------------------------------------------------------------------------
2  *
3  * memcmp.c
4  *        compares memory bytes
5  *
6  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
7  *
8  *
9  * IDENTIFICATION
10  *        $PostgreSQL: pgsql/src/port/memcmp.c,v 1.12 2008/01/01 19:46:00 momjian Exp $
11  *
12  * This file was taken from NetBSD and is used by SunOS because memcmp
13  * on that platform does not properly compare negative bytes. The
14  * NetBSD copyright terms follow.
15  */
16
17 /*-
18  * Copyright (c) 1990, 1993
19  *      The Regents of the University of California.  All rights reserved.
20  *
21  * This code is derived from software contributed to Berkeley by
22  * Chris Torek.
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  * 1. Redistributions of source code must retain the above copyright
28  *        notice, this list of conditions and the following disclaimer.
29  * 2. Redistributions in binary form must reproduce the above copyright
30  *        notice, this list of conditions and the following disclaimer in the
31  *        documentation and/or other materials provided with the distribution.
32  * 3. Neither the name of the University nor the names of its contributors
33  *        may be used to endorse or promote products derived from this software
34  *        without specific prior written permission.
35  *
36  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
37  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39  * ARE DISCLAIMED.      IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
40  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
42  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  */
48
49 #include "c.h"
50
51
52 /*
53  * Compare memory regions.
54  */
55 int
56 memcmp(const void *s1, const void *s2, size_t n)
57 {
58         if (n != 0)
59         {
60                 const unsigned char *p1 = s1,
61                                    *p2 = s2;
62
63                 do
64                 {
65                         if (*p1++ != *p2++)
66                                 return (*--p1 - *--p2);
67                 } while (--n != 0);
68         }
69         return 0;
70 }