Merge commit 'a39d4083cab589d7cd6a13e8a4b8db8875261d75'
[gnulib.git] / lib / bcopy.c
1 /* bcopy.c -- copy memory.
2    Copy LENGTH bytes from SOURCE to DEST.  Does not null-terminate.
3    In the public domain.
4    By David MacKenzie <djm@gnu.ai.mit.edu>.  */
5
6 #include <config.h>
7
8 #include <stddef.h>
9
10 void
11 bcopy (void const *source0, void *dest0, size_t length)
12 {
13   char const *source = source0;
14   char *dest = dest0;
15   if (source < dest)
16     /* Moving from low mem to hi mem; start at end.  */
17     for (source += length, dest += length; length; --length)
18       *--dest = *--source;
19   else if (source != dest)
20     /* Moving from hi mem to low mem; start at beginning.  */
21     for (; length; --length)
22       *dest++ = *source++;
23 }