1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * arch/mips/boot/compressed/string.c
4 *
5 * Very small subset of simple string routines
6 */
7
8 #include <linux/compiler_attributes.h>
9 #include <linux/types.h>
10
memcpy(void * dest,const void * src,size_t n)11 void *memcpy(void *dest, const void *src, size_t n)
12 {
13 int i;
14 const char *s = src;
15 char *d = dest;
16
17 for (i = 0; i < n; i++)
18 d[i] = s[i];
19 return dest;
20 }
21
memset(void * s,int c,size_t n)22 void *memset(void *s, int c, size_t n)
23 {
24 int i;
25 char *ss = s;
26
27 for (i = 0; i < n; i++)
28 ss[i] = c;
29 return s;
30 }
31
memmove(void * dest,const void * src,size_t n)32 void * __weak memmove(void *dest, const void *src, size_t n)
33 {
34 unsigned int i;
35 const char *s = src;
36 char *d = dest;
37
38 if ((uintptr_t)dest < (uintptr_t)src) {
39 for (i = 0; i < n; i++)
40 d[i] = s[i];
41 } else {
42 for (i = n; i > 0; i--)
43 d[i - 1] = s[i - 1];
44 }
45 return dest;
46 }
47