1 /* memmove.c -- copy memory. 2 Copy LENGTH bytes from SOURCE to DEST. Does not null-terminate. 3 In the public domain. 4 By David MacKenzie <djm@gnu.ai.mit.edu>. */ 5 #include <sys/cdefs.h> 6 __RCSID("$NetBSD: memmove.c,v 1.2 2016/05/17 14:00:09 christos Exp $"); 7 8 #ifdef HAVE_CONFIG_H 9 # include <config.h> 10 #endif 11 12 #include <stddef.h> 13 14 void * memmove(void * dest0,void const * source0,size_t length)15memmove (void *dest0, void const *source0, size_t length) 16 { 17 char *dest = dest0; 18 char const *source = source0; 19 if (source < dest) 20 /* Moving from low mem to hi mem; start at end. */ 21 for (source += length, dest += length; length; --length) 22 *--dest = *--source; 23 else if (source != dest) 24 { 25 /* Moving from hi mem to low mem; start at beginning. */ 26 for (; length; --length) 27 *dest++ = *source++; 28 } 29 return dest0; 30 } 31