memmove.c 556 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Id$ */
  6. #include <string.h>
  7. void *
  8. memmove(void *s1, const void *s2, register size_t n)
  9. {
  10. register char *p1 = s1;
  11. register const char *p2 = s2;
  12. if (n>0) {
  13. if (p2 <= p1 && p2 + n > p1) {
  14. /* overlap, copy backwards */
  15. p1 += n;
  16. p2 += n;
  17. n++;
  18. while (--n > 0) {
  19. *--p1 = *--p2;
  20. }
  21. } else {
  22. n++;
  23. while (--n > 0) {
  24. *p1++ = *p2++;
  25. }
  26. }
  27. }
  28. return s1;
  29. }