From 17d2c00994f3e04d0b25dccb00220e69dc8bb443 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Mon, 23 May 2016 23:06:55 +0800 Subject: Clib: Add memmove() to improve portability This patch implements memmove(). Lv Zheng. Signed-off-by: Lv Zheng --- source/components/utilities/utclib.c | 55 ++++++++++++++++++++++++++++++++++++ source/include/acclib.h | 6 ++++ 2 files changed, 61 insertions(+) diff --git a/source/components/utilities/utclib.c b/source/components/utilities/utclib.c index 7e61b980a..0bc9215fd 100644 --- a/source/components/utilities/utclib.c +++ b/source/components/utilities/utclib.c @@ -199,6 +199,61 @@ memcmp ( } +/******************************************************************************* + * + * FUNCTION: memmove + * + * PARAMETERS: Dest - Target of the copy + * Src - Source buffer to copy + * Count - Number of bytes to copy + * + * RETURN: Dest + * + * DESCRIPTION: Copy arbitrary bytes of memory with respect to the overlapping + * + ******************************************************************************/ + +void * +memmove ( + void *Dest, + const void *Src, + ACPI_SIZE Count) +{ + char *New = (char *) Dest; + char *Old = (char *) Src; + + + if (Old > New) + { + /* Copy from the beginning */ + + while (Count) + { + *New = *Old; + New++; + Old++; + Count--; + } + } + else if (Old < New) + { + /* Copy from the end */ + + New = New + Count - 1; + Old = Old + Count - 1; + while (Count) + { + *New = *Old; + New--; + Old--; + Count--; + } + } + + return (Dest); +} + + /******************************************************************************* * * FUNCTION: memcpy diff --git a/source/include/acclib.h b/source/include/acclib.h index 67c05bf36..9f5853596 100644 --- a/source/include/acclib.h +++ b/source/include/acclib.h @@ -236,6 +236,12 @@ memcpy ( const void *Src, ACPI_SIZE Count); +void * +memmove ( + void *Dest, + const void *Src, + ACPI_SIZE Count); + void * memset ( void *Dest, -- cgit v1.2.1