xref: /openbsd-src/gnu/usr.bin/texinfo/lib/memmove.c (revision a1acfa9b69ad64eb720639240c8438f11107dc85)
1840175f0Skstailey /* memmove.c -- copy memory.
2840175f0Skstailey    Copy LENGTH bytes from SOURCE to DEST.  Does not null-terminate.
3840175f0Skstailey    In the public domain.
4840175f0Skstailey    By David MacKenzie <djm@gnu.ai.mit.edu>.  */
5840175f0Skstailey 
63fb98d4aSespie #if HAVE_CONFIG_H
7840175f0Skstailey # include <config.h>
8840175f0Skstailey #endif
9840175f0Skstailey 
10*a1acfa9bSespie #include <stddef.h>
11*a1acfa9bSespie 
123fb98d4aSespie void *
memmove(void * dest0,void const * source0,size_t length)13*a1acfa9bSespie memmove (void *dest0, void const *source0, size_t length)
14840175f0Skstailey {
15*a1acfa9bSespie   char *dest = dest0;
16*a1acfa9bSespie   char const *source = source0;
17840175f0Skstailey   if (source < dest)
18840175f0Skstailey     /* Moving from low mem to hi mem; start at end.  */
19840175f0Skstailey     for (source += length, dest += length; length; --length)
20840175f0Skstailey       *--dest = *--source;
21840175f0Skstailey   else if (source != dest)
223fb98d4aSespie     {
23840175f0Skstailey       /* Moving from hi mem to low mem; start at beginning.  */
24840175f0Skstailey       for (; length; --length)
25840175f0Skstailey 	*dest++ = *source++;
26840175f0Skstailey     }
27*a1acfa9bSespie   return dest0;
283fb98d4aSespie }
29