comparison src/strcmp.c @ 203:850242ba4a81 r20-3b28

Import from CVS: tag r20-3b28
author cvs
date Mon, 13 Aug 2007 10:02:21 +0200
parents 376386a54a3c
children 74fd4e045ea6
comparison
equal deleted inserted replaced
202:61eefc8fc970 203:850242ba4a81
22 following the last byte is not mapped. 22 following the last byte is not mapped.
23 23
24 Here are correct versions by hbs@lucid.com. 24 Here are correct versions by hbs@lucid.com.
25 */ 25 */
26 26
27 # include <config.h>
28 # ifndef REGISTER /* Strictly enforced in 20.3 */
29 # define REGISTER
30 # endif
31
27 #include <string.h> 32 #include <string.h>
28 #define ALIGNED(x) (!(((unsigned long) (x)) & (sizeof (unsigned long) - 1))) 33 #define ALIGNED(x) (!(((unsigned long) (x)) & (sizeof (unsigned long) - 1)))
29 34
30 #define MAGIC 0x7efefeff 35 #define MAGIC 0x7efefeff
31 #define HIGH_BIT_P(c) ((c) & hi_bit) 36 #define HIGH_BIT_P(c) ((c) & hi_bit)
32 #define HAS_ZERO(c) (((((c) + magic) ^ (c)) & not_magic) != not_magic) 37 #define HAS_ZERO(c) (((((c) + magic) ^ (c)) & not_magic) != not_magic)
33 38
39 /* CONST IS LOSING, but const is part of the interface of strcmp */
34 int 40 int
35 strcmp (const char *x, const char *y) 41 strcmp (const char *x, const char *y)
36 { 42 {
37 if (x == y) 43 if (x == y)
38 return 0; 44 return 0;
39 else if (ALIGNED (x) && ALIGNED (y)) 45 else if (ALIGNED (x) && ALIGNED (y))
40 { 46 {
41 const unsigned long *x1 = (const unsigned long *) x; 47 CONST unsigned long *x1 = (CONST unsigned long *) x;
42 const unsigned long *y1 = (const unsigned long *) y; 48 CONST unsigned long *y1 = (CONST unsigned long *) y;
43 unsigned long c; 49 unsigned long c;
44 unsigned long magic = MAGIC; 50 unsigned long magic = MAGIC;
45 unsigned long not_magic = ~magic; 51 unsigned long not_magic = ~magic;
46 unsigned long hi_bit = 0x80000000; 52 unsigned long hi_bit = 0x80000000;
47 53
51 { 57 {
52 if (!HIGH_BIT_P (c)) 58 if (!HIGH_BIT_P (c))
53 return 0; 59 return 0;
54 else 60 else
55 { 61 {
56 x = (const char *) x1; 62 x = (CONST char *) x1;
57 y = (const char *) y1; 63 y = (CONST char *) y1;
58 goto slow_loop; 64 goto slow_loop;
59 } 65 }
60 } 66 }
61 67
62 x1++; 68 x1++;
63 y1++; 69 y1++;
64 } 70 }
65 71
66 x = (const char *) x1; 72 x = (CONST char *) x1;
67 y = (const char *) y1; 73 y = (CONST char *) y1;
68 goto slow_loop; 74 goto slow_loop;
69 } 75 }
70 else 76 else
71 { 77 {
72 char c; 78 char c;
83 } 89 }
84 } 90 }
85 91
86 92
87 int 93 int
88 strncmp (const char *x, const char *y, size_t n) 94 strncmp (CONST char *x, CONST char *y, size_t n)
89 { 95 {
90 if ((x == y) || (n <= 0)) 96 if ((x == y) || (n <= 0))
91 return 0; 97 return 0;
92 else if (ALIGNED (x) && ALIGNED (y)) 98 else if (ALIGNED (x) && ALIGNED (y))
93 { 99 {
94 const unsigned long *x1 = (const unsigned long *) x; 100 CONST unsigned long *x1 = (CONST unsigned long *) x;
95 const unsigned long *y1 = (const unsigned long *) y; 101 CONST unsigned long *y1 = (CONST unsigned long *) y;
96 unsigned long c; 102 unsigned long c;
97 unsigned long magic = MAGIC; 103 unsigned long magic = MAGIC;
98 unsigned long not_magic = ~magic; 104 unsigned long not_magic = ~magic;
99 unsigned long hi_bit = 0x80000000; 105 unsigned long hi_bit = 0x80000000;
100 106
108 { 114 {
109 if (!HIGH_BIT_P (c)) 115 if (!HIGH_BIT_P (c))
110 return 0; 116 return 0;
111 else 117 else
112 { 118 {
113 x = (const char *) x1; 119 x = (CONST char *) x1;
114 y = (const char *) y1; 120 y = (CONST char *) y1;
115 goto slow_loop; 121 goto slow_loop;
116 } 122 }
117 } 123 }
118 124
119 x1++; 125 x1++;
120 y1++; 126 y1++;
121 } 127 }
122 128
123 x = (const char *) x1; 129 x = (CONST char *) x1;
124 y = (const char *) y1; 130 y = (CONST char *) y1;
125 goto slow_loop; 131 goto slow_loop;
126 } 132 }
127 else 133 else
128 { 134 {
129 char c; 135 char c;