memmove.c 887 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. libc_hidden_proto(memmove)
  12. # define Wmemmove memmove
  13. #endif
  14. Wvoid *Wmemmove(Wvoid *s1, const Wvoid *s2, size_t n)
  15. {
  16. #ifdef __BCC__
  17. register Wchar *s = (Wchar *) s1;
  18. register const Wchar *p = (const Wchar *) s2;
  19. if (p >= s) {
  20. while (n--) {
  21. *s++ = *p++;
  22. }
  23. } else {
  24. s += n;
  25. p += n;
  26. while (n--) {
  27. *--s = *--p;
  28. }
  29. }
  30. return s1;
  31. #else
  32. register Wchar *s = (Wchar *) s1;
  33. register const Wchar *p = (const Wchar *) s2;
  34. if (p >= s) {
  35. while (n) {
  36. *s++ = *p++;
  37. --n;
  38. }
  39. } else {
  40. while (n) {
  41. --n;
  42. s[n] = p[n];
  43. }
  44. }
  45. return s1;
  46. #endif
  47. }
  48. #ifndef WANT_WIDE
  49. libc_hidden_def(Wmemmove)
  50. #endif