diff options
Diffstat (limited to 'lib/memmove.c')
-rw-r--r-- | lib/memmove.c | 55 |
1 files changed, 13 insertions, 42 deletions
diff --git a/lib/memmove.c b/lib/memmove.c index e674c49..81f00fe 100644 --- a/lib/memmove.c +++ b/lib/memmove.c @@ -1,49 +1,20 @@ -/** -** @file memmove.c -** -** @author Numerous CSCI-452 classes -** -** @brief C implementations of common library functions -*/ +#include <string.h> -#ifndef MEMMOVE_SRC_INC -#define MEMMOVE_SRC_INC - -#include <common.h> - -#include <lib.h> - -/** -** 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) +void *memmove(void *dest, const void *src, size_t n) { - register uint8_t *dest = dst; - register const uint8_t *source = src; + char *d = dest; + const char *s = src; - /* - ** We could speed this up by unrolling it and copying - ** words at a time (instead of bytes). - */ + if (d == s) + return d; - if (source < dest && (source + len) > dest) { - source += len; - dest += len; - while (len-- > 0) { - *--dest = *--source; - } + if (d < s) { + for (; n; n--) + *d++ = *s++; } else { - while (len--) { - *dest++ = *source++; - } + while (n) + n--, d[n] = s[n]; } -} -#endif + return dest; +} |