18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * arch/mips/boot/compressed/string.c
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Very small subset of simple string routines
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/compiler_attributes.h>
98c2ecf20Sopenharmony_ci#include <linux/types.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_civoid *memcpy(void *dest, const void *src, size_t n)
128c2ecf20Sopenharmony_ci{
138c2ecf20Sopenharmony_ci	int i;
148c2ecf20Sopenharmony_ci	const char *s = src;
158c2ecf20Sopenharmony_ci	char *d = dest;
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci	for (i = 0; i < n; i++)
188c2ecf20Sopenharmony_ci		d[i] = s[i];
198c2ecf20Sopenharmony_ci	return dest;
208c2ecf20Sopenharmony_ci}
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_civoid *memset(void *s, int c, size_t n)
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	int i;
258c2ecf20Sopenharmony_ci	char *ss = s;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	for (i = 0; i < n; i++)
288c2ecf20Sopenharmony_ci		ss[i] = c;
298c2ecf20Sopenharmony_ci	return s;
308c2ecf20Sopenharmony_ci}
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_civoid * __weak memmove(void *dest, const void *src, size_t n)
338c2ecf20Sopenharmony_ci{
348c2ecf20Sopenharmony_ci	unsigned int i;
358c2ecf20Sopenharmony_ci	const char *s = src;
368c2ecf20Sopenharmony_ci	char *d = dest;
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	if ((uintptr_t)dest < (uintptr_t)src) {
398c2ecf20Sopenharmony_ci		for (i = 0; i < n; i++)
408c2ecf20Sopenharmony_ci			d[i] = s[i];
418c2ecf20Sopenharmony_ci	} else {
428c2ecf20Sopenharmony_ci		for (i = n; i > 0; i--)
438c2ecf20Sopenharmony_ci			d[i - 1] = s[i - 1];
448c2ecf20Sopenharmony_ci	}
458c2ecf20Sopenharmony_ci	return dest;
468c2ecf20Sopenharmony_ci}
47