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.

105 lines
3.2 KiB

  1. /***
  2. *memmove.c - contains memmove routine
  3. *
  4. * Copyright (c) 1988-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * memmove() copies a source memory buffer to a destination buffer.
  8. * Overlapping buffers are treated specially, to avoid propogation.
  9. *
  10. *Revision History:
  11. * 05-31-89 JCR C version created.
  12. * 02-27-90 GJF Fixed calling type, #include <cruntime.h>, fixed
  13. * copyright.
  14. * 10-01-90 GJF New-style function declarator. Also, rewrote expr. to
  15. * avoid using cast as an lvalue.
  16. * 12-28-90 SRW Added cast of void * to char * for Mips C Compiler
  17. * 04-09-91 GJF Speed up a little for large buffers.
  18. * 08-06-91 GJF Backed out 04-09-91 change. Pointers would have to be
  19. * dword-aligned for this to work on MIPS.
  20. * 07-16-93 SRW ALPHA Merge
  21. * 09-01-93 GJF Merged NT SDK and Cuda versions.
  22. * 11-12-93 GJF Replace _MIPS_ and _ALPHA_ with _M_MRX000 and
  23. * _M_ALPHA (resp.).
  24. * 10-02-94 BWT Add function pragma for Alpha and PPC support
  25. * 10-07-97 RDL Added IA64.
  26. * 04-30-01 BWT Add AMD64.
  27. *
  28. *******************************************************************************/
  29. #include <cruntime.h>
  30. #include <string.h>
  31. /***
  32. *memmove - Copy source buffer to destination buffer
  33. *
  34. *Purpose:
  35. * memmove() copies a source memory buffer to a destination memory buffer.
  36. * This routine recognize overlapping buffers to avoid propogation.
  37. * For cases where propogation is not a problem, memcpy() can be used.
  38. *
  39. *Entry:
  40. * void *dst = pointer to destination buffer
  41. * const void *src = pointer to source buffer
  42. * size_t count = number of bytes to copy
  43. *
  44. *Exit:
  45. * Returns a pointer to the destination buffer
  46. *
  47. *Exceptions:
  48. *******************************************************************************/
  49. void * __cdecl memmove (
  50. void * dst,
  51. const void * src,
  52. size_t count
  53. )
  54. {
  55. void * ret = dst;
  56. #if defined(_M_IA64) || defined(_M_AMD64)
  57. {
  58. #if !defined(LIBCNTPR)
  59. __declspec(dllimport)
  60. #endif
  61. void RtlMoveMemory( void *, const void *, size_t count );
  62. RtlMoveMemory( dst, src, count );
  63. }
  64. #else
  65. if (dst <= src || (char *)dst >= ((char *)src + count)) {
  66. /*
  67. * Non-Overlapping Buffers
  68. * copy from lower addresses to higher addresses
  69. */
  70. while (count--) {
  71. *(char *)dst = *(char *)src;
  72. dst = (char *)dst + 1;
  73. src = (char *)src + 1;
  74. }
  75. }
  76. else {
  77. /*
  78. * Overlapping Buffers
  79. * copy from higher addresses to lower addresses
  80. */
  81. dst = (char *)dst + count - 1;
  82. src = (char *)src + count - 1;
  83. while (count--) {
  84. *(char *)dst = *(char *)src;
  85. dst = (char *)dst - 1;
  86. src = (char *)src - 1;
  87. }
  88. }
  89. #endif
  90. return(ret);
  91. }