Leaked source code of windows server 2003
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.

106 lines
3.3 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. * 07-15-01 PML Remove all ALPHA, MIPS, and PPC code
  28. *
  29. *******************************************************************************/
  30. #include <cruntime.h>
  31. #include <string.h>
  32. /***
  33. *memmove - Copy source buffer to destination buffer
  34. *
  35. *Purpose:
  36. * memmove() copies a source memory buffer to a destination memory buffer.
  37. * This routine recognize overlapping buffers to avoid propogation.
  38. * For cases where propogation is not a problem, memcpy() can be used.
  39. *
  40. *Entry:
  41. * void *dst = pointer to destination buffer
  42. * const void *src = pointer to source buffer
  43. * size_t count = number of bytes to copy
  44. *
  45. *Exit:
  46. * Returns a pointer to the destination buffer
  47. *
  48. *Exceptions:
  49. *******************************************************************************/
  50. void * __cdecl memmove (
  51. void * dst,
  52. const void * src,
  53. size_t count
  54. )
  55. {
  56. void * ret = dst;
  57. #if defined(_M_IA64) || defined(_M_AMD64)
  58. {
  59. #if !defined(LIBCNTPR)
  60. __declspec(dllimport)
  61. #endif
  62. void RtlMoveMemory( void *, const void *, size_t count );
  63. RtlMoveMemory( dst, src, count );
  64. }
  65. #else
  66. if (dst <= src || (char *)dst >= ((char *)src + count)) {
  67. /*
  68. * Non-Overlapping Buffers
  69. * copy from lower addresses to higher addresses
  70. */
  71. while (count--) {
  72. *(char *)dst = *(char *)src;
  73. dst = (char *)dst + 1;
  74. src = (char *)src + 1;
  75. }
  76. }
  77. else {
  78. /*
  79. * Overlapping Buffers
  80. * copy from higher addresses to lower addresses
  81. */
  82. dst = (char *)dst + count - 1;
  83. src = (char *)src + count - 1;
  84. while (count--) {
  85. *(char *)dst = *(char *)src;
  86. dst = (char *)dst - 1;
  87. src = (char *)src - 1;
  88. }
  89. }
  90. #endif
  91. return(ret);
  92. }