2 This file is part of SXEmacs
4 SXEmacs is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 SXEmacs is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* Synched up with: Not in FSF. */
20 /* In SunOS 4.1.1 the strcmp and strncmp functions reference memory
21 past the last byte of the string! This will core dump if the memory
22 following the last byte is not mapped.
24 Here are correct versions by hbs@lucid.com.
28 # ifndef REGISTER /* Strictly enforced in 20.3 */
33 #define ALIGNED(x) (!(((unsigned long) (x)) & (sizeof (unsigned long) - 1)))
35 #define MAGIC 0x7efefeff
36 #define HIGH_BIT_P(c) ((c) & hi_bit)
37 #define HAS_ZERO(c) (((((c) + magic) ^ (c)) & not_magic) != not_magic)
39 int strcmp(const char *x, const char *y)
43 else if (ALIGNED(x) && ALIGNED(y)) {
44 const unsigned long *x1 = (const unsigned long *)x;
45 const unsigned long *y1 = (const unsigned long *)y;
47 unsigned long magic = MAGIC;
48 unsigned long not_magic = ~magic;
49 unsigned long hi_bit = 0x80000000;
51 while ((c = *x1) == *y1) {
74 while ((c = *x) == *y) {
84 int strncmp(const char *x, const char *y, size_t n)
86 if ((x == y) || (n <= 0))
88 else if (ALIGNED(x) && ALIGNED(y)) {
89 const unsigned long *x1 = (const unsigned long *)x;
90 const unsigned long *y1 = (const unsigned long *)y;
92 unsigned long magic = MAGIC;
93 unsigned long not_magic = ~magic;
94 unsigned long hi_bit = 0x80000000;
96 while ((c = *x1) == *y1) {
97 n -= sizeof(unsigned long);
105 x = (const char *)x1;
106 y = (const char *)y1;
115 x = (const char *)x1;
116 y = (const char *)y1;
123 while ((c = *x) == *y) {