blob: ba176fb08f73710fc0d22bbec4312108517fa8d1 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * linux/lib/string.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
6
7/*
8 * stupid library routines.. The optimized versions should generally be found
9 * as inline code in <asm-xx/string.h>
10 *
11 * These are buggy as well..
12 *
13 * * Fri Jun 25 1999, Ingo Oeser <ioe@informatik.tu-chemnitz.de>
14 * - Added strsep() which will replace strtok() soon (because strsep() is
15 * reentrant and should be faster). Use only strsep() in new code, please.
16 */
17
Simon Glass96794a32018-11-06 15:21:38 -070018#include <config.h>
Marek BehĂșn46c3e292021-05-20 13:23:55 +020019#include <linux/compiler.h>
wdenkc6097192002-11-03 00:24:07 +000020#include <linux/types.h>
21#include <linux/string.h>
22#include <linux/ctype.h>
23#include <malloc.h>
24
wdenkc6097192002-11-03 00:24:07 +000025
wdenkc6097192002-11-03 00:24:07 +000026/**
Simon Glassb1f17bf2012-12-05 14:46:35 +000027 * strncasecmp - Case insensitive, length-limited string comparison
wdenkc6097192002-11-03 00:24:07 +000028 * @s1: One string
29 * @s2: The other string
30 * @len: the maximum number of characters to compare
31 */
Simon Glassb1f17bf2012-12-05 14:46:35 +000032int strncasecmp(const char *s1, const char *s2, size_t len)
wdenkc6097192002-11-03 00:24:07 +000033{
34 /* Yes, Virginia, it had better be unsigned */
35 unsigned char c1, c2;
36
37 c1 = 0; c2 = 0;
38 if (len) {
39 do {
40 c1 = *s1; c2 = *s2;
41 s1++; s2++;
42 if (!c1)
43 break;
44 if (!c2)
45 break;
46 if (c1 == c2)
47 continue;
48 c1 = tolower(c1);
49 c2 = tolower(c2);
50 if (c1 != c2)
51 break;
52 } while (--len);
53 }
54 return (int)c1 - (int)c2;
55}
Simon Glassb1f17bf2012-12-05 14:46:35 +000056
57/**
58 * strcasecmp - Case insensitive string comparison
59 * @s1: One string
60 * @s2: The other string
61 */
62int strcasecmp(const char *s1, const char *s2)
63{
64 return strncasecmp(s1, s2, -1U);
65}
wdenkc6097192002-11-03 00:24:07 +000066
67char * ___strtok;
68
69#ifndef __HAVE_ARCH_STRCPY
70/**
71 * strcpy - Copy a %NUL terminated string
72 * @dest: Where to copy the string to
73 * @src: Where to copy the string from
74 */
75char * strcpy(char * dest,const char *src)
76{
77 char *tmp = dest;
78
79 while ((*dest++ = *src++) != '\0')
80 /* nothing */;
81 return tmp;
82}
83#endif
84
85#ifndef __HAVE_ARCH_STRNCPY
86/**
87 * strncpy - Copy a length-limited, %NUL-terminated string
88 * @dest: Where to copy the string to
89 * @src: Where to copy the string from
90 * @count: The maximum number of bytes to copy
91 *
92 * Note that unlike userspace strncpy, this does not %NUL-pad the buffer.
93 * However, the result is not %NUL-terminated if the source exceeds
94 * @count bytes.
95 */
96char * strncpy(char * dest,const char *src,size_t count)
97{
98 char *tmp = dest;
99
100 while (count-- && (*dest++ = *src++) != '\0')
101 /* nothing */;
102
103 return tmp;
104}
105#endif
106
Masahiro Yamada80d9ef82014-11-20 21:20:32 +0900107#ifndef __HAVE_ARCH_STRLCPY
108/**
109 * strlcpy - Copy a C-string into a sized buffer
110 * @dest: Where to copy the string to
111 * @src: Where to copy the string from
112 * @size: size of destination buffer
113 *
114 * Compatible with *BSD: the result is always a valid
115 * NUL-terminated string that fits in the buffer (unless,
116 * of course, the buffer size is zero). It does not pad
117 * out the result like strncpy() does.
Sean Andersond3358ec2021-03-11 00:15:41 -0500118 *
119 * Return: the number of bytes copied
Masahiro Yamada80d9ef82014-11-20 21:20:32 +0900120 */
121size_t strlcpy(char *dest, const char *src, size_t size)
122{
Masahiro Yamada80d9ef82014-11-20 21:20:32 +0900123 if (size) {
Sean Andersond3358ec2021-03-11 00:15:41 -0500124 size_t srclen = strlen(src);
125 size_t len = (srclen >= size) ? size - 1 : srclen;
126
Masahiro Yamada80d9ef82014-11-20 21:20:32 +0900127 memcpy(dest, src, len);
128 dest[len] = '\0';
Sean Andersond3358ec2021-03-11 00:15:41 -0500129 return len + 1;
Masahiro Yamada80d9ef82014-11-20 21:20:32 +0900130 }
Sean Andersond3358ec2021-03-11 00:15:41 -0500131
132 return 0;
Masahiro Yamada80d9ef82014-11-20 21:20:32 +0900133}
134#endif
135
wdenkc6097192002-11-03 00:24:07 +0000136#ifndef __HAVE_ARCH_STRCAT
137/**
138 * strcat - Append one %NUL-terminated string to another
139 * @dest: The string to be appended to
140 * @src: The string to append to it
141 */
142char * strcat(char * dest, const char * src)
143{
144 char *tmp = dest;
145
146 while (*dest)
147 dest++;
148 while ((*dest++ = *src++) != '\0')
149 ;
150
151 return tmp;
152}
153#endif
154
155#ifndef __HAVE_ARCH_STRNCAT
156/**
157 * strncat - Append a length-limited, %NUL-terminated string to another
158 * @dest: The string to be appended to
159 * @src: The string to append to it
160 * @count: The maximum numbers of bytes to copy
161 *
162 * Note that in contrast to strncpy, strncat ensures the result is
163 * terminated.
164 */
165char * strncat(char *dest, const char *src, size_t count)
166{
167 char *tmp = dest;
168
169 if (count) {
170 while (*dest)
171 dest++;
172 while ((*dest++ = *src++)) {
173 if (--count == 0) {
174 *dest = '\0';
175 break;
176 }
177 }
178 }
179
180 return tmp;
181}
182#endif
183
Sean Anderson9af869c2021-03-11 00:15:42 -0500184#ifndef __HAVE_ARCH_STRLCAT
185/**
186 * strlcat - Append a length-limited, %NUL-terminated string to another
187 * @dest: The string to be appended to
188 * @src: The string to append to it
189 * @size: The size of @dest
190 *
191 * Compatible with *BSD: the result is always a valid NUL-terminated string that
192 * fits in the buffer (unless, of course, the buffer size is zero). It does not
193 * write past @size like strncat() does.
194 */
195size_t strlcat(char *dest, const char *src, size_t size)
196{
197 size_t len = strnlen(dest, size);
198
199 return len + strlcpy(dest + len, src, size - len);
200}
201#endif
202
wdenkc6097192002-11-03 00:24:07 +0000203#ifndef __HAVE_ARCH_STRCMP
204/**
205 * strcmp - Compare two strings
206 * @cs: One string
207 * @ct: Another string
208 */
209int strcmp(const char * cs,const char * ct)
210{
211 register signed char __res;
212
213 while (1) {
214 if ((__res = *cs - *ct++) != 0 || !*cs++)
215 break;
216 }
217
218 return __res;
219}
220#endif
221
222#ifndef __HAVE_ARCH_STRNCMP
223/**
224 * strncmp - Compare two length-limited strings
225 * @cs: One string
226 * @ct: Another string
227 * @count: The maximum number of bytes to compare
228 */
229int strncmp(const char * cs,const char * ct,size_t count)
230{
231 register signed char __res = 0;
232
233 while (count) {
234 if ((__res = *cs - *ct++) != 0 || !*cs++)
235 break;
236 count--;
237 }
238
239 return __res;
240}
241#endif
242
243#ifndef __HAVE_ARCH_STRCHR
244/**
245 * strchr - Find the first occurrence of a character in a string
246 * @s: The string to be searched
247 * @c: The character to search for
248 */
249char * strchr(const char * s, int c)
250{
251 for(; *s != (char) c; ++s)
252 if (*s == '\0')
253 return NULL;
254 return (char *) s;
255}
256#endif
257
Simon Glass6b45ba42017-05-18 20:09:28 -0600258const char *strchrnul(const char *s, int c)
259{
260 for (; *s != (char)c; ++s)
261 if (*s == '\0')
262 break;
263 return s;
264}
265
wdenkc6097192002-11-03 00:24:07 +0000266#ifndef __HAVE_ARCH_STRRCHR
267/**
268 * strrchr - Find the last occurrence of a character in a string
269 * @s: The string to be searched
270 * @c: The character to search for
271 */
272char * strrchr(const char * s, int c)
273{
274 const char *p = s + strlen(s);
275 do {
wdenk8bde7f72003-06-27 21:31:46 +0000276 if (*p == (char)c)
277 return (char *)p;
wdenkc6097192002-11-03 00:24:07 +0000278 } while (--p >= s);
279 return NULL;
280}
281#endif
282
283#ifndef __HAVE_ARCH_STRLEN
284/**
285 * strlen - Find the length of a string
286 * @s: The string to be sized
287 */
288size_t strlen(const char * s)
289{
290 const char *sc;
291
292 for (sc = s; *sc != '\0'; ++sc)
293 /* nothing */;
294 return sc - s;
295}
296#endif
297
298#ifndef __HAVE_ARCH_STRNLEN
299/**
300 * strnlen - Find the length of a length-limited string
301 * @s: The string to be sized
302 * @count: The maximum number of bytes to search
303 */
304size_t strnlen(const char * s, size_t count)
305{
306 const char *sc;
307
308 for (sc = s; count-- && *sc != '\0'; ++sc)
309 /* nothing */;
310 return sc - s;
311}
312#endif
313
Simon Glassa7d00212017-05-18 20:09:29 -0600314#ifndef __HAVE_ARCH_STRCSPN
315/**
316 * strcspn - Calculate the length of the initial substring of @s which does
317 * not contain letters in @reject
318 * @s: The string to be searched
319 * @reject: The string to avoid
320 */
321size_t strcspn(const char *s, const char *reject)
322{
323 const char *p;
324 const char *r;
325 size_t count = 0;
326
327 for (p = s; *p != '\0'; ++p) {
328 for (r = reject; *r != '\0'; ++r) {
329 if (*p == *r)
330 return count;
331 }
332 ++count;
333 }
334 return count;
335}
336#endif
337
wdenkc6097192002-11-03 00:24:07 +0000338#ifndef __HAVE_ARCH_STRDUP
339char * strdup(const char *s)
340{
341 char *new;
342
343 if ((s == NULL) ||
344 ((new = malloc (strlen(s) + 1)) == NULL) ) {
345 return NULL;
346 }
347
348 strcpy (new, s);
349 return new;
350}
wdenkc6097192002-11-03 00:24:07 +0000351
Thierry Reding0c4e2652019-04-15 11:32:14 +0200352char * strndup(const char *s, size_t n)
353{
354 size_t len;
355 char *new;
356
357 if (s == NULL)
358 return NULL;
359
360 len = strlen(s);
361
362 if (n < len)
363 len = n;
364
365 new = malloc(len + 1);
366 if (new == NULL)
367 return NULL;
368
369 strncpy(new, s, len);
370 new[len] = '\0';
371
372 return new;
373}
Simon Glass1ea1c7d2020-02-03 07:36:00 -0700374#endif
Thierry Reding0c4e2652019-04-15 11:32:14 +0200375
wdenkc6097192002-11-03 00:24:07 +0000376#ifndef __HAVE_ARCH_STRSPN
377/**
378 * strspn - Calculate the length of the initial substring of @s which only
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200379 * contain letters in @accept
wdenkc6097192002-11-03 00:24:07 +0000380 * @s: The string to be searched
381 * @accept: The string to search for
382 */
383size_t strspn(const char *s, const char *accept)
384{
385 const char *p;
386 const char *a;
387 size_t count = 0;
388
389 for (p = s; *p != '\0'; ++p) {
390 for (a = accept; *a != '\0'; ++a) {
391 if (*p == *a)
392 break;
393 }
394 if (*a == '\0')
395 return count;
396 ++count;
397 }
398
399 return count;
400}
401#endif
402
403#ifndef __HAVE_ARCH_STRPBRK
404/**
405 * strpbrk - Find the first occurrence of a set of characters
406 * @cs: The string to be searched
407 * @ct: The characters to search for
408 */
409char * strpbrk(const char * cs,const char * ct)
410{
411 const char *sc1,*sc2;
412
413 for( sc1 = cs; *sc1 != '\0'; ++sc1) {
414 for( sc2 = ct; *sc2 != '\0'; ++sc2) {
415 if (*sc1 == *sc2)
416 return (char *) sc1;
417 }
418 }
419 return NULL;
420}
421#endif
422
423#ifndef __HAVE_ARCH_STRTOK
424/**
425 * strtok - Split a string into tokens
426 * @s: The string to be searched
427 * @ct: The characters to search for
428 *
429 * WARNING: strtok is deprecated, use strsep instead.
430 */
431char * strtok(char * s,const char * ct)
432{
433 char *sbegin, *send;
434
435 sbegin = s ? s : ___strtok;
436 if (!sbegin) {
437 return NULL;
438 }
439 sbegin += strspn(sbegin,ct);
440 if (*sbegin == '\0') {
441 ___strtok = NULL;
442 return( NULL );
443 }
444 send = strpbrk( sbegin, ct);
445 if (send && *send != '\0')
446 *send++ = '\0';
447 ___strtok = send;
448 return (sbegin);
449}
450#endif
451
452#ifndef __HAVE_ARCH_STRSEP
453/**
454 * strsep - Split a string into tokens
455 * @s: The string to be searched
456 * @ct: The characters to search for
457 *
458 * strsep() updates @s to point after the token, ready for the next call.
459 *
460 * It returns empty tokens, too, behaving exactly like the libc function
461 * of that name. In fact, it was stolen from glibc2 and de-fancy-fied.
462 * Same semantics, slimmer shape. ;)
463 */
464char * strsep(char **s, const char *ct)
465{
466 char *sbegin = *s, *end;
467
468 if (sbegin == NULL)
469 return NULL;
470
471 end = strpbrk(sbegin, ct);
472 if (end)
473 *end++ = '\0';
474 *s = end;
475
476 return sbegin;
477}
478#endif
479
wdenkc3f9d492004-03-14 00:59:59 +0000480#ifndef __HAVE_ARCH_STRSWAB
481/**
482 * strswab - swap adjacent even and odd bytes in %NUL-terminated string
483 * s: address of the string
484 *
485 * returns the address of the swapped string or NULL on error. If
486 * string length is odd, last byte is untouched.
487 */
488char *strswab(const char *s)
489{
Wolfgang Denk389db1f2005-09-25 16:15:17 +0200490 char *p, *q;
wdenkc3f9d492004-03-14 00:59:59 +0000491
492 if ((NULL == s) || ('\0' == *s)) {
493 return (NULL);
494 }
495
Wolfgang Denke5e98ed2005-10-04 23:38:07 +0200496 for (p=(char *)s, q=p+1; (*p != '\0') && (*q != '\0'); p+=2, q+=2) {
wdenkc3f9d492004-03-14 00:59:59 +0000497 char tmp;
Wolfgang Denk389db1f2005-09-25 16:15:17 +0200498
499 tmp = *p;
500 *p = *q;
501 *q = tmp;
wdenkc3f9d492004-03-14 00:59:59 +0000502 }
503
504 return (char *) s;
505}
506#endif
507
wdenkc6097192002-11-03 00:24:07 +0000508#ifndef __HAVE_ARCH_MEMSET
509/**
510 * memset - Fill a region of memory with the given value
511 * @s: Pointer to the start of the area.
512 * @c: The byte to fill the area with
513 * @count: The size of the area.
514 *
515 * Do not use memset() to access IO space, use memset_io() instead.
516 */
Marek BehĂșn46c3e292021-05-20 13:23:55 +0200517__used void * memset(void * s,int c,size_t count)
wdenkc6097192002-11-03 00:24:07 +0000518{
Alessandro Rubinie3ea9482009-10-10 11:51:16 +0200519 unsigned long *sl = (unsigned long *) s;
Alessandro Rubinie3ea9482009-10-10 11:51:16 +0200520 char *s8;
Simon Glassab4458b2017-04-02 09:50:28 -0600521
522#if !CONFIG_IS_ENABLED(TINY_MEMSET)
523 unsigned long cl = 0;
Alessandro Rubinie3ea9482009-10-10 11:51:16 +0200524 int i;
wdenkc6097192002-11-03 00:24:07 +0000525
Alessandro Rubinie3ea9482009-10-10 11:51:16 +0200526 /* do it one word at a time (32 bits or 64 bits) while possible */
527 if ( ((ulong)s & (sizeof(*sl) - 1)) == 0) {
528 for (i = 0; i < sizeof(*sl); i++) {
529 cl <<= 8;
530 cl |= c & 0xff;
531 }
532 while (count >= sizeof(*sl)) {
533 *sl++ = cl;
534 count -= sizeof(*sl);
535 }
536 }
Simon Glassab4458b2017-04-02 09:50:28 -0600537#endif /* fill 8 bits at a time */
Alessandro Rubinie3ea9482009-10-10 11:51:16 +0200538 s8 = (char *)sl;
wdenkc6097192002-11-03 00:24:07 +0000539 while (count--)
Alessandro Rubinie3ea9482009-10-10 11:51:16 +0200540 *s8++ = c;
wdenkc6097192002-11-03 00:24:07 +0000541
542 return s;
543}
544#endif
545
wdenkc6097192002-11-03 00:24:07 +0000546#ifndef __HAVE_ARCH_MEMCPY
547/**
548 * memcpy - Copy one area of memory to another
549 * @dest: Where to copy to
550 * @src: Where to copy from
551 * @count: The size of the area.
552 *
553 * You should not use this function to access IO space, use memcpy_toio()
554 * or memcpy_fromio() instead.
555 */
Marek BehĂșn46c3e292021-05-20 13:23:55 +0200556__used void * memcpy(void *dest, const void *src, size_t count)
wdenkc6097192002-11-03 00:24:07 +0000557{
Alessandro Rubiniecd830b2009-10-10 11:51:05 +0200558 unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src;
559 char *d8, *s8;
wdenkc6097192002-11-03 00:24:07 +0000560
Matthias Weisserb038db82011-05-22 23:03:55 +0000561 if (src == dest)
562 return dest;
563
Alessandro Rubiniecd830b2009-10-10 11:51:05 +0200564 /* while all data is aligned (common case), copy a word at a time */
565 if ( (((ulong)dest | (ulong)src) & (sizeof(*dl) - 1)) == 0) {
566 while (count >= sizeof(*dl)) {
567 *dl++ = *sl++;
568 count -= sizeof(*dl);
569 }
570 }
571 /* copy the reset one byte at a time */
572 d8 = (char *)dl;
573 s8 = (char *)sl;
wdenkc6097192002-11-03 00:24:07 +0000574 while (count--)
Alessandro Rubiniecd830b2009-10-10 11:51:05 +0200575 *d8++ = *s8++;
wdenkc6097192002-11-03 00:24:07 +0000576
577 return dest;
578}
579#endif
580
581#ifndef __HAVE_ARCH_MEMMOVE
582/**
583 * memmove - Copy one area of memory to another
584 * @dest: Where to copy to
585 * @src: Where to copy from
586 * @count: The size of the area.
587 *
588 * Unlike memcpy(), memmove() copes with overlapping areas.
589 */
Marek BehĂșn46c3e292021-05-20 13:23:55 +0200590__used void * memmove(void * dest,const void *src,size_t count)
wdenkc6097192002-11-03 00:24:07 +0000591{
592 char *tmp, *s;
593
Patrick Delaunay976a68a2020-12-11 14:59:23 +0100594 if (dest <= src || (src + count) <= dest) {
595 /*
596 * Use the fast memcpy implementation (ARCH optimized or lib/string.c) when it is possible:
597 * - when dest is before src (assuming that memcpy is doing forward-copying)
598 * - when destination don't overlap the source buffer (src + count <= dest)
599 *
600 * WARNING: the first optimisation cause an issue, when __HAVE_ARCH_MEMCPY is defined,
601 * __HAVE_ARCH_MEMMOVE is not defined and if the memcpy ARCH-specific
602 * implementation is not doing a forward-copying.
603 *
604 * No issue today because memcpy is doing a forward-copying in lib/string.c and for ARM32
605 * architecture; no other arches use __HAVE_ARCH_MEMCPY without __HAVE_ARCH_MEMMOVE.
606 */
Simon Glasscb0eae82017-04-05 16:23:31 -0600607 memcpy(dest, src, count);
608 } else {
wdenkc6097192002-11-03 00:24:07 +0000609 tmp = (char *) dest + count;
610 s = (char *) src + count;
611 while (count--)
612 *--tmp = *--s;
613 }
614
615 return dest;
616}
617#endif
618
619#ifndef __HAVE_ARCH_MEMCMP
620/**
621 * memcmp - Compare two areas of memory
622 * @cs: One area of memory
623 * @ct: Another area of memory
624 * @count: The size of the area.
625 */
Marek BehĂșn46c3e292021-05-20 13:23:55 +0200626__used int memcmp(const void * cs,const void * ct,size_t count)
wdenkc6097192002-11-03 00:24:07 +0000627{
628 const unsigned char *su1, *su2;
629 int res = 0;
630
631 for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
632 if ((res = *su1 - *su2) != 0)
633 break;
634 return res;
635}
636#endif
637
638#ifndef __HAVE_ARCH_MEMSCAN
639/**
640 * memscan - Find a character in an area of memory.
641 * @addr: The memory area
642 * @c: The byte to search for
643 * @size: The size of the area.
644 *
645 * returns the address of the first occurrence of @c, or 1 byte past
646 * the area if @c is not found
647 */
648void * memscan(void * addr, int c, size_t size)
649{
650 unsigned char * p = (unsigned char *) addr;
651
652 while (size) {
653 if (*p == c)
654 return (void *) p;
655 p++;
656 size--;
657 }
wdenk8bde7f72003-06-27 21:31:46 +0000658 return (void *) p;
wdenkc6097192002-11-03 00:24:07 +0000659}
660#endif
661
662#ifndef __HAVE_ARCH_STRSTR
663/**
664 * strstr - Find the first substring in a %NUL terminated string
665 * @s1: The string to be searched
666 * @s2: The string to search for
667 */
668char * strstr(const char * s1,const char * s2)
669{
670 int l1, l2;
671
672 l2 = strlen(s2);
673 if (!l2)
674 return (char *) s1;
675 l1 = strlen(s1);
676 while (l1 >= l2) {
677 l1--;
678 if (!memcmp(s1,s2,l2))
679 return (char *) s1;
680 s1++;
681 }
682 return NULL;
683}
684#endif
685
686#ifndef __HAVE_ARCH_MEMCHR
687/**
688 * memchr - Find a character in an area of memory.
689 * @s: The memory area
690 * @c: The byte to search for
691 * @n: The size of the area.
692 *
693 * returns the address of the first occurrence of @c, or %NULL
694 * if @c is not found
695 */
696void *memchr(const void *s, int c, size_t n)
697{
698 const unsigned char *p = s;
699 while (n-- != 0) {
wdenk8bde7f72003-06-27 21:31:46 +0000700 if ((unsigned char)c == *p++) {
wdenkc6097192002-11-03 00:24:07 +0000701 return (void *)(p-1);
702 }
703 }
704 return NULL;
705}
706
707#endif
Sergey Lapindfe64e22013-01-14 03:46:50 +0000708#ifndef __HAVE_ARCH_MEMCHR_INV
709static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes)
710{
711 while (bytes) {
712 if (*start != value)
713 return (void *)start;
714 start++;
715 bytes--;
716 }
717 return NULL;
718}
719/**
720 * memchr_inv - Find an unmatching character in an area of memory.
721 * @start: The memory area
722 * @c: Find a character other than c
723 * @bytes: The size of the area.
724 *
725 * returns the address of the first character other than @c, or %NULL
726 * if the whole buffer contains just @c.
727 */
728void *memchr_inv(const void *start, int c, size_t bytes)
729{
730 u8 value = c;
731 u64 value64;
732 unsigned int words, prefix;
733
734 if (bytes <= 16)
735 return check_bytes8(start, value, bytes);
736
737 value64 = value;
738 value64 |= value64 << 8;
739 value64 |= value64 << 16;
740 value64 |= value64 << 32;
741
742 prefix = (unsigned long)start % 8;
743 if (prefix) {
744 u8 *r;
745
746 prefix = 8 - prefix;
747 r = check_bytes8(start, value, prefix);
748 if (r)
749 return r;
750 start += prefix;
751 bytes -= prefix;
752 }
753
754 words = bytes / 8;
755
756 while (words) {
757 if (*(u64 *)start != value64)
758 return check_bytes8(start, value, 8);
759 start += 8;
760 words--;
761 }
762
763 return check_bytes8(start, value, bytes % 8);
764}
765#endif