memmove.c 673 B

1234567891011121314151617181920212223242526
  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>. */
  5. #include <config.h>
  6. #include <stddef.h>
  7. void *
  8. memmove (void *dest0, void const *source0, size_t length)
  9. {
  10. char *dest = dest0;
  11. char const *source = source0;
  12. if (source < dest)
  13. /* Moving from low mem to hi mem; start at end. */
  14. for (source += length, dest += length; length; --length)
  15. *--dest = *--source;
  16. else if (source != dest)
  17. {
  18. /* Moving from hi mem to low mem; start at beginning. */
  19. for (; length; --length)
  20. *dest++ = *source++;
  21. }
  22. return dest0;
  23. }