Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / arm / boot / compressed / string.c
blob13c90abc68d68a9c5a73502beacb17aef1c89132
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * arch/arm/boot/compressed/string.c
5 * Small subset of simple string routines
6 */
8 #include <linux/string.h>
10 void *memcpy(void *__dest, __const void *__src, size_t __n)
12 int i = 0;
13 unsigned char *d = (unsigned char *)__dest, *s = (unsigned char *)__src;
15 for (i = __n >> 3; i > 0; i--) {
16 *d++ = *s++;
17 *d++ = *s++;
18 *d++ = *s++;
19 *d++ = *s++;
20 *d++ = *s++;
21 *d++ = *s++;
22 *d++ = *s++;
23 *d++ = *s++;
26 if (__n & 1 << 2) {
27 *d++ = *s++;
28 *d++ = *s++;
29 *d++ = *s++;
30 *d++ = *s++;
33 if (__n & 1 << 1) {
34 *d++ = *s++;
35 *d++ = *s++;
38 if (__n & 1)
39 *d++ = *s++;
41 return __dest;
44 void *memmove(void *__dest, __const void *__src, size_t count)
46 unsigned char *d = __dest;
47 const unsigned char *s = __src;
49 if (__dest == __src)
50 return __dest;
52 if (__dest < __src)
53 return memcpy(__dest, __src, count);
55 while (count--)
56 d[count] = s[count];
57 return __dest;
60 size_t strlen(const char *s)
62 const char *sc = s;
64 while (*sc != '\0')
65 sc++;
66 return sc - s;
69 size_t strnlen(const char *s, size_t count)
71 const char *sc;
73 for (sc = s; count-- && *sc != '\0'; ++sc)
74 /* nothing */;
75 return sc - s;
78 int memcmp(const void *cs, const void *ct, size_t count)
80 const unsigned char *su1 = cs, *su2 = ct, *end = su1 + count;
81 int res = 0;
83 while (su1 < end) {
84 res = *su1++ - *su2++;
85 if (res)
86 break;
88 return res;
91 int strcmp(const char *cs, const char *ct)
93 unsigned char c1, c2;
94 int res = 0;
96 do {
97 c1 = *cs++;
98 c2 = *ct++;
99 res = c1 - c2;
100 if (res)
101 break;
102 } while (c1);
103 return res;
106 void *memchr(const void *s, int c, size_t count)
108 const unsigned char *p = s;
110 while (count--)
111 if ((unsigned char)c == *p++)
112 return (void *)(p - 1);
113 return NULL;
116 char *strchr(const char *s, int c)
118 while (*s != (char)c)
119 if (*s++ == '\0')
120 return NULL;
121 return (char *)s;
124 #undef memset
126 void *memset(void *s, int c, size_t count)
128 char *xs = s;
129 while (count--)
130 *xs++ = c;
131 return s;