From 0ff301cda68669c59351e5854ce98f2cf460543f Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Thu, 27 Mar 2025 11:39:12 -0400 Subject: pull upstream changes, add auto formatting --- lib/memmove.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lib/memmove.c (limited to 'lib/memmove.c') diff --git a/lib/memmove.c b/lib/memmove.c new file mode 100644 index 0000000..e674c49 --- /dev/null +++ b/lib/memmove.c @@ -0,0 +1,49 @@ +/** +** @file memmove.c +** +** @author Numerous CSCI-452 classes +** +** @brief C implementations of common library functions +*/ + +#ifndef MEMMOVE_SRC_INC +#define MEMMOVE_SRC_INC + +#include + +#include + +/** +** memmove(dst,src,len) +** +** Copy a block from one place to another. Deals with overlapping +** buffers. +** +** @param dst Destination buffer +** @param src Source buffer +** @param len Buffer size (in bytes) +*/ +void memmove(void *dst, const void *src, register uint32_t len) +{ + register uint8_t *dest = dst; + register const uint8_t *source = src; + + /* + ** We could speed this up by unrolling it and copying + ** words at a time (instead of bytes). + */ + + if (source < dest && (source + len) > dest) { + source += len; + dest += len; + while (len-- > 0) { + *--dest = *--source; + } + } else { + while (len--) { + *dest++ = *source++; + } + } +} + +#endif -- cgit v1.2.3-freya