diff options
author | Freya Murphy <freya@freyacat.org> | 2025-03-27 11:39:12 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-03-27 11:39:12 -0400 |
commit | 0ff301cda68669c59351e5854ce98f2cf460543f (patch) | |
tree | cfe8f976261962420ada64b821559b9da0a56841 /lib/memmove.c | |
parent | add compile_flags.txt for clangd lsp (diff) | |
download | comus-0ff301cda68669c59351e5854ce98f2cf460543f.tar.gz comus-0ff301cda68669c59351e5854ce98f2cf460543f.tar.bz2 comus-0ff301cda68669c59351e5854ce98f2cf460543f.zip |
pull upstream changes, add auto formatting
Diffstat (limited to 'lib/memmove.c')
-rw-r--r-- | lib/memmove.c | 49 |
1 files changed, 49 insertions, 0 deletions
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 <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) +{ + 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 |