memmove.c 860 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (C) 2002 Manuel Novoa III
  3. * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. #include "_string.h"
  8. #ifdef WANT_WIDE
  9. # define Wmemmove wmemmove
  10. #else
  11. # define Wmemmove memmove
  12. #endif
  13. Wvoid *Wmemmove(Wvoid *s1, const Wvoid *s2, size_t n)
  14. {
  15. #ifdef __BCC__
  16. register Wchar *s = (Wchar *) s1;
  17. register const Wchar *p = (const Wchar *) s2;
  18. if (p >= s) {
  19. while (n--) {
  20. *s++ = *p++;
  21. }
  22. } else {
  23. s += n;
  24. p += n;
  25. while (n--) {
  26. *--s = *--p;
  27. }
  28. }
  29. return s1;
  30. #else
  31. register Wchar *s = (Wchar *) s1;
  32. register const Wchar *p = (const Wchar *) s2;
  33. if (p >= s) {
  34. while (n) {
  35. *s++ = *p++;
  36. --n;
  37. }
  38. } else {
  39. while (n) {
  40. --n;
  41. s[n] = p[n];
  42. }
  43. }
  44. return s1;
  45. #endif
  46. }
  47. #ifndef WANT_WIDE
  48. libc_hidden_def(Wmemmove)
  49. #endif