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

  1. /***
  2. *memccpy.c - copy bytes until a character is found
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines _memccpy() - copies bytes until a specifed character
  8. *       is found, or a maximum number of characters have been copied.
  9. *
  10. *******************************************************************************/
  11.  
  12. #include <cruntime.h>
  13. #include <string.h>
  14.  
  15. /***
  16. *char *_memccpy(dest, src, c, count) - copy bytes until character found
  17. *
  18. *Purpose:
  19. *       Copies bytes from src to dest until count bytes have been
  20. *       copied, or up to and including the character c, whichever
  21. *       comes first.
  22. *
  23. *Entry:
  24. *       void *dest - pointer to memory to receive copy
  25. *       void *src  - source of bytes
  26. *       int  c     - character to stop copy at
  27. *       unsigned int count - max number of bytes to copy
  28. *
  29. *Exit:
  30. *       returns pointer to byte immediately after c in dest
  31. *       returns NULL if c was never found
  32. *
  33. *Exceptions:
  34. *
  35. *******************************************************************************/
  36.  
  37. void * __cdecl _memccpy (
  38.         void * dest,
  39.         const void * src,
  40.         int c,
  41.         unsigned count
  42.         )
  43. {
  44.         while ( count && (*((char *)(dest = (char *)dest + 1) - 1) =
  45.         *((char *)(src = (char *)src + 1) - 1)) != (char)c )
  46.                 count--;
  47.  
  48.         return(count ? dest : NULL);
  49. }
  50.