Blame gettext-runtime/gnulib-lib/memmove.c
|
Packit Bot |
06c835 |
/* memmove.c -- copy memory.
|
|
Packit Bot |
06c835 |
Copy LENGTH bytes from SOURCE to DEST. Does not null-terminate.
|
|
Packit Bot |
06c835 |
In the public domain.
|
|
Packit Bot |
06c835 |
By David MacKenzie <djm@gnu.ai.mit.edu>. */
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
#include <config.h>
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
#include <stddef.h>
|
|
Packit Bot |
06c835 |
|
|
Packit Bot |
06c835 |
void *
|
|
Packit Bot |
06c835 |
memmove (void *dest0, void const *source0, size_t length)
|
|
Packit Bot |
06c835 |
{
|
|
Packit Bot |
06c835 |
char *dest = dest0;
|
|
Packit Bot |
06c835 |
char const *source = source0;
|
|
Packit Bot |
06c835 |
if (source < dest)
|
|
Packit Bot |
06c835 |
/* Moving from low mem to hi mem; start at end. */
|
|
Packit Bot |
06c835 |
for (source += length, dest += length; length; --length)
|
|
Packit Bot |
06c835 |
*--dest = *--source;
|
|
Packit Bot |
06c835 |
else if (source != dest)
|
|
Packit Bot |
06c835 |
{
|
|
Packit Bot |
06c835 |
/* Moving from hi mem to low mem; start at beginning. */
|
|
Packit Bot |
06c835 |
for (; length; --length)
|
|
Packit Bot |
06c835 |
*dest++ = *source++;
|
|
Packit Bot |
06c835 |
}
|
|
Packit Bot |
06c835 |
return dest0;
|
|
Packit Bot |
06c835 |
}
|