1 /* $NetBSD: memmove.c,v 1.1.1.1 2016/01/14 00:11:29 christos Exp $ */ 2 3 /* memmove.c -- copy memory. 4 Copy LENGTH bytes from SOURCE to DEST. Does not null-terminate. 5 In the public domain. 6 By David MacKenzie <djm@gnu.ai.mit.edu>. */ 7 8 #if 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