home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / memcpy.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  2KB  |  67 lines

  1. /***
  2. *memcpy.c - contains memcpy routine
  3. *
  4. *       Copyright (c) 1988-1997, Microsoft Corporation. All right 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. *******************************************************************************/
  11.  
  12. #include <cruntime.h>
  13. #include <string.h>
  14.  
  15. #ifdef _MSC_VER
  16. #pragma function(memcpy)
  17. #endif  /* _MSC_VER */
  18.  
  19. /***
  20. *memcpy - Copy source buffer to destination buffer
  21. *
  22. *Purpose:
  23. *       memcpy() copies a source memory buffer to a destination memory buffer.
  24. *       This routine does NOT recognize overlapping buffers, and thus can lead
  25. *       to propogation.
  26. *
  27. *       For cases where propogation must be avoided, memmove() must be used.
  28. *
  29. *Entry:
  30. *       void *dst = pointer to destination buffer
  31. *       const void *src = pointer to source buffer
  32. *       size_t count = number of bytes to copy
  33. *
  34. *Exit:
  35. *       Returns a pointer to the destination buffer
  36. *
  37. *Exceptions:
  38. *******************************************************************************/
  39.  
  40. void * __cdecl memcpy (
  41.         void * dst,
  42.         const void * src,
  43.         size_t count
  44.         )
  45. {
  46.         void * ret = dst;
  47.  
  48. #if defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC)
  49.         {
  50.         extern void RtlMoveMemory( void *, const void *, size_t count );
  51.  
  52.         RtlMoveMemory( dst, src, count );
  53.         }
  54. #else  /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
  55.         /*
  56.          * copy from lower addresses to higher addresses
  57.          */
  58.         while (count--) {
  59.                 *(char *)dst = *(char *)src;
  60.                 dst = (char *)dst + 1;
  61.                 src = (char *)src + 1;
  62.         }
  63. #endif  /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
  64.  
  65.         return(ret);
  66. }
  67.