summaryrefslogtreecommitdiffstats
path: root/arch/mips/boot/compressed/string.c
blob: f0eb251e44e5a8341dd10b8c1135bbda4018f093 (plain)
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
37
38
39
40
41
42
43
44
45
46
47
// SPDX-License-Identifier: GPL-2.0
/*
 * arch/mips/boot/compressed/string.c
 *
 * Very small subset of simple string routines
 */

#include <linux/compiler_attributes.h>
#include <linux/types.h>
#include <asm/string.h>

void *memcpy(void *dest, const void *src, size_t n)
{
	int i;
	const char *s = src;
	char *d = dest;

	for (i = 0; i < n; i++)
		d[i] = s[i];
	return dest;
}

void *memset(void *s, int c, size_t n)
{
	int i;
	char *ss = s;

	for (i = 0; i < n; i++)
		ss[i] = c;
	return s;
}

void * __weak memmove(void *dest, const void *src, size_t n)
{
	unsigned int i;
	const char *s = src;
	char *d = dest;

	if ((uintptr_t)dest < (uintptr_t)src) {
		for (i = 0; i < n; i++)
			d[i] = s[i];
	} else {
		for (i = n; i > 0; i--)
			d[i - 1] = s[i - 1];
	}
	return dest;
}