diff options
author | des <des@FreeBSD.org> | 2013-04-05 09:43:20 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2013-04-05 09:43:20 +0000 |
commit | b0cbd784b12baa8ea27f7196e9a297847e8284c1 (patch) | |
tree | 6870f089d4472a1bab1bf9bb01ff61d3709c049f /contrib/unbound/compat/memmove.c | |
parent | 47b0933c6d1f9070043e74cfaaaab8a03ba2b47d (diff) | |
parent | 30c2432cb51cf03a3f4028c24488b364925a5d89 (diff) | |
download | FreeBSD-src-b0cbd784b12baa8ea27f7196e9a297847e8284c1.zip FreeBSD-src-b0cbd784b12baa8ea27f7196e9a297847e8284c1.tar.gz |
Minimal subset of the unbound sources.
Diffstat (limited to 'contrib/unbound/compat/memmove.c')
-rw-r--r-- | contrib/unbound/compat/memmove.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/contrib/unbound/compat/memmove.c b/contrib/unbound/compat/memmove.c new file mode 100644 index 0000000..0035bbf --- /dev/null +++ b/contrib/unbound/compat/memmove.c @@ -0,0 +1,43 @@ +/* + * memmove.c: memmove compat implementation. + * + * Copyright (c) 2001-2006, NLnet Labs. All rights reserved. + * + * See LICENSE for the license. +*/ + +#include <config.h> +#include <stdlib.h> + +void *memmove(void *dest, const void *src, size_t n); + +void *memmove(void *dest, const void *src, size_t n) +{ + uint8_t* from = (uint8_t*) src; + uint8_t* to = (uint8_t*) dest; + + if (from == to || n == 0) + return dest; + if (to > from && to-from < (int)n) { + /* to overlaps with from */ + /* <from......> */ + /* <to........> */ + /* copy in reverse, to avoid overwriting from */ + int i; + for(i=n-1; i>=0; i--) + to[i] = from[i]; + return dest; + } + if (from > to && from-to < (int)n) { + /* to overlaps with from */ + /* <from......> */ + /* <to........> */ + /* copy forwards, to avoid overwriting from */ + size_t i; + for(i=0; i<n; i++) + to[i] = from[i]; + return dest; + } + memcpy(dest, src, n); + return dest; +} |