1995-01-27 19:32:16 +00:00
|
|
|
/* memmove.c -- copy memory.
|
|
|
|
|
Copy LENGTH bytes from SOURCE to DEST. Does not null-terminate.
|
|
|
|
|
In the public domain.
|
|
|
|
|
By David MacKenzie <djm@gnu.ai.mit.edu>. */
|
|
|
|
|
|
1996-10-17 03:05:09 +00:00
|
|
|
#if HAVE_CONFIG_H
|
1996-07-15 02:29:59 +00:00
|
|
|
# include <config.h>
|
1995-05-21 11:44:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
2003-09-10 09:03:31 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
1996-07-14 15:05:40 +00:00
|
|
|
void *
|
2003-09-10 09:03:31 +00:00
|
|
|
memmove (void *dest0, void const *source0, size_t length)
|
1995-01-27 19:32:16 +00:00
|
|
|
{
|
2003-09-10 09:03:31 +00:00
|
|
|
char *dest = dest0;
|
|
|
|
|
char const *source = source0;
|
1995-01-27 19:32:16 +00:00
|
|
|
if (source < dest)
|
|
|
|
|
/* Moving from low mem to hi mem; start at end. */
|
|
|
|
|
for (source += length, dest += length; length; --length)
|
|
|
|
|
*--dest = *--source;
|
|
|
|
|
else if (source != dest)
|
1996-07-14 15:05:40 +00:00
|
|
|
{
|
|
|
|
|
/* Moving from hi mem to low mem; start at beginning. */
|
|
|
|
|
for (; length; --length)
|
|
|
|
|
*dest++ = *source++;
|
|
|
|
|
}
|
2003-09-10 09:03:31 +00:00
|
|
|
return dest0;
|
1995-01-27 19:32:16 +00:00
|
|
|
}
|