Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.2 KiB

  1. #include "precomp.h"
  2. // In debug mode, we link with CRT, so we don't need this!
  3. #ifndef _DEBUG
  4. /***
  5. *memmove.c - contains memmove routine
  6. *
  7. * Copyright (c) 1988-1997, Microsoft Corporation. All right reserved.
  8. *
  9. *Purpose:
  10. * memmove() copies a source memory buffer to a destination buffer.
  11. * Overlapping buffers are treated specially, to avoid propogation.
  12. *
  13. *******************************************************************************/
  14. #if defined (_M_ALPHA)
  15. #pragma function(memmove)
  16. #endif /* defined (_M_ALPHA) */
  17. /***
  18. *memmove - Copy source buffer to destination buffer
  19. *
  20. *Purpose:
  21. * memmove() copies a source memory buffer to a destination memory buffer.
  22. * This routine recognize overlapping buffers to avoid propogation.
  23. * For cases where propogation is not a problem, memcpy() can be used.
  24. *
  25. *Entry:
  26. * void *dst = pointer to destination buffer
  27. * const void *src = pointer to source buffer
  28. * size_t count = number of bytes to copy
  29. *
  30. *Exit:
  31. * Returns a pointer to the destination buffer
  32. *
  33. *Exceptions:
  34. *******************************************************************************/
  35. void * __cdecl memmove (
  36. void * dst,
  37. const void * src,
  38. size_t count
  39. )
  40. {
  41. void * ret = dst;
  42. #if defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC)
  43. {
  44. extern void RtlMoveMemory( void *, const void *, size_t count );
  45. RtlMoveMemory( dst, src, count );
  46. }
  47. #else /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
  48. if (dst <= src || (char *)dst >= ((char *)src + count)) {
  49. /*
  50. * Non-Overlapping Buffers
  51. * copy from lower addresses to higher addresses
  52. */
  53. while (count--) {
  54. *(char *)dst = *(char *)src;
  55. dst = (char *)dst + 1;
  56. src = (char *)src + 1;
  57. }
  58. }
  59. else {
  60. /*
  61. * Overlapping Buffers
  62. * copy from higher addresses to lower addresses
  63. */
  64. dst = (char *)dst + count - 1;
  65. src = (char *)src + count - 1;
  66. while (count--) {
  67. *(char *)dst = *(char *)src;
  68. dst = (char *)dst - 1;
  69. src = (char *)src - 1;
  70. }
  71. }
  72. #endif /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
  73. return(ret);
  74. }
  75. #endif // !_DEBUG