summaryrefslogtreecommitdiffstats
path: root/private/crt32/string/memccpy.c
blob: 2fd8f63cdb451ab4238f77d6d48d6803a6644ab4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/***
*memccpy.c - copy bytes until a character is found
*
*	Copyright (c) 1985-1991, Microsoft Corporation. All rights reserved.
*
*Purpose:
*	defines _memccpy() - copies bytes until a specifed character
*	is found, or a maximum number of characters have been copied.
*
*Revision History:
*	05-31-89   JCR	C version created.
*	02-27-90   GJF	Fixed calling type, #include <cruntime.h>, fixed
*			copyright. Also, fixed compiler warning.
*	08-14-90   SBM	Compiles cleanly with -W3, removed now redundant
*			#include <stddef.h>
*	10-01-90   GJF	New-style function declarator. Also, rewrote expr. to
*			avoid using cast as an lvalue.
*	01-17-91   GJF	ANSI naming.
*
*******************************************************************************/

#include <cruntime.h>
#include <string.h>

/***
*char *_memccpy(dest, src, c, count) - copy bytes until character found
*
*Purpose:
*	Copies bytes from src to dest until count bytes have been
*	copied, or up to and including the character c, whichever
*	comes first.
*
*Entry:
*	void *dest - pointer to memory to receive copy
*	void *src  - source of bytes
*	int  c     - character to stop copy at
*	unsigned int count - max number of bytes to copy
*
*Exit:
*	returns pointer to byte immediately after c in dest
*	returns NULL if c was never found
*
*Exceptions:
*
*******************************************************************************/

void * _CALLTYPE1 _memccpy (
	void * dest,
	const void * src,
	int c,
	unsigned count
	)
{
	while ( count && (*((char *)(dest = (char *)dest + 1) - 1) =
	*((char *)(src = (char *)src + 1) - 1)) != (char)c )
		count--;

	return(count ? dest : NULL);
}