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.

97 lines
2.8 KiB

  1. /***
  2. *memcpy.c - contains memcpy routine
  3. *
  4. * Copyright (c) 1988-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * memcpy() copies a source memory buffer to a destination buffer.
  8. * Overlapping buffers are not treated specially, so propogation may occur.
  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. * 04-01-91 SRW Add #pragma function for i386 _WIN32_ and _CRUISER_
  17. * builds
  18. * 04-05-91 GJF Speed up for large buffers by moving int-sized chunks
  19. * as much as possible.
  20. * 08-06-91 GJF Backed out 04-05-91 change. Pointers would have to be
  21. * dword-aligned for this to work on MIPS.
  22. * 07-16-93 SRW ALPHA Merge
  23. * 09-01-93 GJF Merged NT SDK and Cuda versions.
  24. * 11-12-93 GJF Replace _MIPS_ and _ALPHA_ with _M_MRX000 and
  25. * _M_ALPHA (resp.).
  26. * 12-03-93 GJF Turn on #pragma function for all MS front-ends (esp.,
  27. * Alpha compiler).
  28. * 10-02-94 BWT Add PPC support.
  29. * 10-07-97 RDL Added IA64.
  30. *
  31. *******************************************************************************/
  32. #include <cruntime.h>
  33. #include <string.h>
  34. #ifdef _MSC_VER
  35. #pragma function(memcpy)
  36. #endif
  37. /***
  38. *memcpy - Copy source buffer to destination buffer
  39. *
  40. *Purpose:
  41. * memcpy() copies a source memory buffer to a destination memory buffer.
  42. * This routine does NOT recognize overlapping buffers, and thus can lead
  43. * to propogation.
  44. *
  45. * For cases where propogation must be avoided, memmove() must be used.
  46. *
  47. *Entry:
  48. * void *dst = pointer to destination buffer
  49. * const void *src = pointer to source buffer
  50. * size_t count = number of bytes to copy
  51. *
  52. *Exit:
  53. * Returns a pointer to the destination buffer
  54. *
  55. *Exceptions:
  56. *******************************************************************************/
  57. void * __cdecl memcpy (
  58. void * dst,
  59. const void * src,
  60. size_t count
  61. )
  62. {
  63. void * ret = dst;
  64. #if defined(_M_IA64) || defined(_M_AMD64)
  65. {
  66. #if !defined(LIBCNTPR)
  67. __declspec(dllimport)
  68. #endif
  69. void RtlCopyMemory( void *, const void *, size_t count );
  70. RtlCopyMemory( dst, src, count );
  71. }
  72. #else
  73. /*
  74. * copy from lower addresses to higher addresses
  75. */
  76. while (count--) {
  77. *(char *)dst = *(char *)src;
  78. dst = (char *)dst + 1;
  79. src = (char *)src + 1;
  80. }
  81. #endif
  82. return(ret);
  83. }