|
|
1.1 root 1: /* memcmp -- compare two memory regions.
2: Copyright (C) 1991 Free Software Foundation, Inc.
3:
4: This file is part of the libiberty library.
5: Libiberty is free software; you can redistribute it and/or
6: modify it under the terms of the GNU Library General Public
7: License as published by the Free Software Foundation; either
8: version 2 of the License, or (at your option) any later version.
9:
10: Libiberty is distributed in the hope that it will be useful,
11: but WITHOUT ANY WARRANTY; without even the implied warranty of
12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: Library General Public License for more details.
14:
15: You should have received a copy of the GNU Library General Public
16: License along with libiberty; see the file COPYING.LIB. If
17: not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18: Cambridge, MA 02139, USA. */
19:
20:
21: /*
22:
23: NAME
24:
25: memcmp -- compare two memory regions
26:
27: SYNOPSIS
28:
29: int memcmp (const void *from, const void *to, size_t count)
30:
31: DESCRIPTION
32:
33: Compare two memory regions and return less than,
34: equal to, or greater than zero, according to lexicographical
35: ordering of the compared regions.
36: */
37:
38: #include <ansidecl.h>
39: #ifdef __STDC__
40: #include <stddef.h>
41: #else
42: #define size_t unsigned long
43: #endif
44:
45: int
46: DEFUN(memcmp, (str1, str2, count),
47: PTRCONST str1 AND PTRCONST str2 AND size_t count)
48: {
49: register unsigned char *s1 = (unsigned char*)str1;
50: register unsigned char *s2 = (unsigned char*)str2;
51:
52: while (count-- > 0)
53: {
54: if (*s1++ != *s2++)
55: return s1[-1] < s2[-1] ? -1 : 1;
56: }
57: return 0;
58: }
59:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.