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.

61 lines
1.9 KiB

  1. /***
  2. *memccpy.c - copy bytes until a character is found
  3. *
  4. * Copyright (c) 1985-2001, 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. *Revision History:
  11. * 05-31-89 JCR C version created.
  12. * 02-27-90 GJF Fixed calling type, #include <cruntime.h>, fixed
  13. * copyright. Also, fixed compiler warning.
  14. * 08-14-90 SBM Compiles cleanly with -W3, removed now redundant
  15. * #include <stddef.h>
  16. * 10-01-90 GJF New-style function declarator. Also, rewrote expr. to
  17. * avoid using cast as an lvalue.
  18. * 01-17-91 GJF ANSI naming.
  19. * 09-01-93 GJF Replaced _CALLTYPE1 with __cdecl.
  20. * 10-27-99 PML Win64 fix: unsigned int -> size_t
  21. *
  22. *******************************************************************************/
  23. #include <cruntime.h>
  24. #include <string.h>
  25. /***
  26. *char *_memccpy(dest, src, c, count) - copy bytes until character found
  27. *
  28. *Purpose:
  29. * Copies bytes from src to dest until count bytes have been
  30. * copied, or up to and including the character c, whichever
  31. * comes first.
  32. *
  33. *Entry:
  34. * void *dest - pointer to memory to receive copy
  35. * void *src - source of bytes
  36. * int c - character to stop copy at
  37. * size_t count - max number of bytes to copy
  38. *
  39. *Exit:
  40. * returns pointer to byte immediately after c in dest
  41. * returns NULL if c was never found
  42. *
  43. *Exceptions:
  44. *
  45. *******************************************************************************/
  46. void * __cdecl _memccpy (
  47. void * dest,
  48. const void * src,
  49. int c,
  50. size_t count
  51. )
  52. {
  53. while ( count && (*((char *)(dest = (char *)dest + 1) - 1) =
  54. *((char *)(src = (char *)src + 1) - 1)) != (char)c )
  55. count--;
  56. return(count ? dest : NULL);
  57. }