1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| | #include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "word.h"
/**
* strcmp - Word sized c standard strcmp.
* @c: Comparative
* @s: Source
*/
#undef strcmp
int strcmp(const char *c, const char *s)
{
const size_t *wc, *ws;
if ((uintptr_t)c % sizeof(size_t) != (uintptr_t)s % sizeof(size_t))
goto misaligned;
for (; (uintptr_t)c % sizeof(size_t); c++, s++) {
if (*c != *s || !*c || !*s)
return *(const unsigned char *)c
- *(const unsigned char *)s;
}
for (wc = (const size_t *)c, ws = (const size_t *)s
; (!word_has_zero(*wc) || !word_has_zero(*ws)) && *wc == *ws
; wc++, ws++);
c = (const char *)wc;
s = (const char *)ws;
misaligned:
for(; *c == *s && *c && *s; c++, s++);
return *(const unsigned char *)c - *(const unsigned char *)s;
}
|