/*1* memmove.c: memmove compat implementation.2*3* Copyright (c) 2001-2008, NLnet Labs. All rights reserved.4*5* See LICENSE for the license.6*/78#include <ldns/config.h>9#include <stdlib.h>1011void *memmove(void *dest, const void *src, size_t n);1213void *memmove(void *dest, const void *src, size_t n)14{15uint8_t* from = (uint8_t*) src;16uint8_t* to = (uint8_t*) dest;1718if (from == to || n == 0)19return dest;20if (to > from && to-from < (int)n) {21/* to overlaps with from */22/* <from......> */23/* <to........> */24/* copy in reverse, to avoid overwriting from */25int i;26for(i=n-1; i>=0; i--)27to[i] = from[i];28return dest;29}30if (from > to && from-to < (int)n) {31/* to overlaps with from */32/* <from......> */33/* <to........> */34/* copy forwards, to avoid overwriting from */35size_t i;36for(i=0; i<n; i++)37to[i] = from[i];38return dest;39}40memcpy(dest, src, n);41return dest;42}434445