add copyright/no-warranty comment
[coreutils.git] / lib / memmove.c
blobea38e8df549e9e1210c0a38bbe8ed08e45a93603
1 /* memmove.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>. */
6 #if HAVE_CONFIG_H
7 # include <config.h>
8 #endif
10 void *
11 memmove (dest, source, length)
12 char *dest;
13 const char *source;
14 unsigned length;
16 char *d0 = dest;
17 if (source < dest)
18 /* Moving from low mem to hi mem; start at end. */
19 for (source += length, dest += length; length; --length)
20 *--dest = *--source;
21 else if (source != dest)
23 /* Moving from hi mem to low mem; start at beginning. */
24 for (; length; --length)
25 *dest++ = *source++;
27 return (void *) d0;