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

  1. /***
  2. *memset.c - set a section of memory to all one byte
  3. *
  4. *       Copyright (c) 1988-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       contains the memset() routine
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <string.h>
  13.  
  14. #ifdef _MSC_VER
  15. #pragma function(memset)
  16. #endif  /* _MSC_VER */
  17.  
  18. /***
  19. *char *memset(dst, val, count) - sets "count" bytes at "dst" to "val"
  20. *
  21. *Purpose:
  22. *       Sets the first "count" bytes of the memory starting
  23. *       at "dst" to the character value "val".
  24. *
  25. *Entry:
  26. *       void *dst - pointer to memory to fill with val
  27. *       int val   - value to put in dst bytes
  28. *       size_t count - number of bytes of dst to fill
  29. *
  30. *Exit:
  31. *       returns dst, with filled bytes
  32. *
  33. *Exceptions:
  34. *
  35. *******************************************************************************/
  36.  
  37. void * __cdecl memset (
  38.         void *dst,
  39.         int val,
  40.         size_t count
  41.         )
  42. {
  43.         void *start = dst;
  44.  
  45. #if defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC)
  46.         {
  47.         extern void RtlFillMemory( void *, size_t count, char );
  48.  
  49.         RtlFillMemory( dst, count, (char)val );
  50.         }
  51. #else  /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
  52.         while (count--) {
  53.                 *(char *)dst = (char)val;
  54.                 dst = (char *)dst + 1;
  55.         }
  56. #endif  /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
  57.  
  58.         return(start);
  59. }
  60.