aboutsummaryrefslogtreecommitdiff
path: root/lib/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/string.c')
-rw-r--r--lib/string.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/lib/string.c b/lib/string.c
index 43d0781daf4..81a0ae6558e 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -26,6 +26,7 @@
#include <linux/export.h>
#include <linux/bug.h>
#include <linux/errno.h>
+#include <linux/memcopy.h>
#ifndef __HAVE_ARCH_STRNICMP
/**
@@ -614,11 +615,11 @@ EXPORT_SYMBOL(memzero_explicit);
*/
void *memcpy(void *dest, const void *src, size_t count)
{
- char *tmp = dest;
- const char *s = src;
+ unsigned long dstp = (unsigned long)dest;
+ unsigned long srcp = (unsigned long)src;
- while (count--)
- *tmp++ = *s++;
+ /* Copy from the beginning to the end */
+ mem_copy_fwd(dstp, srcp, count);
return dest;
}
EXPORT_SYMBOL(memcpy);
@@ -635,21 +636,15 @@ EXPORT_SYMBOL(memcpy);
*/
void *memmove(void *dest, const void *src, size_t count)
{
- char *tmp;
- const char *s;
+ unsigned long dstp = (unsigned long)dest;
+ unsigned long srcp = (unsigned long)src;
- if (dest <= src) {
- tmp = dest;
- s = src;
- while (count--)
- *tmp++ = *s++;
+ if (dest - src >= count) {
+ /* Copy from the beginning to the end */
+ mem_copy_fwd(dstp, srcp, count);
} else {
- tmp = dest;
- tmp += count;
- s = src;
- s += count;
- while (count--)
- *--tmp = *--s;
+ /* Copy from the end to the beginning */
+ mem_copy_bwd(dstp, srcp, count);
}
return dest;
}