Back to index

tetex-bin  3.0
memmove.c
Go to the documentation of this file.
00001 /* memmove.c -- copy memory.
00002    Copy LENGTH bytes from SOURCE to DEST.  Does not null-terminate.
00003    In the public domain.
00004    By David MacKenzie <djm@gnu.ai.mit.edu>.  */
00005 
00006 #if HAVE_CONFIG_H
00007 # include <config.h>
00008 #endif
00009 
00010 #include <stddef.h>
00011 
00012 void *
00013 memmove (void *dest0, void const *source0, size_t length)
00014 {
00015   char *dest = dest0;
00016   char const *source = source0;
00017   if (source < dest)
00018     /* Moving from low mem to hi mem; start at end.  */
00019     for (source += length, dest += length; length; --length)
00020       *--dest = *--source;
00021   else if (source != dest)
00022     {
00023       /* Moving from hi mem to low mem; start at beginning.  */
00024       for (; length; --length)
00025        *dest++ = *source++;
00026     }
00027   return dest0;
00028 }