summaryrefslogtreecommitdiffstats
path: root/private/crt32/string/memcpy.c
blob: a4348e74ece5842dc4aa279aa2a4942ff6943b90 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/***
*memcpy.c - contains memcpy routine
*
*	Copyright (c) 1988-1991, Microsoft Corporation. All right reserved.
*
*Purpose:
*	memcpy() copies a source memory buffer to a destination buffer.
*	Overlapping buffers are not treated specially, so propogation may occur.
*
*Revision History:
*	05-31-89   JCR	C version created.
*	02-27-90   GJF	Fixed calling type, #include <cruntime.h>, fixed
*			copyright.
*	10-01-90   GJF	New-style function declarator. Also, rewrote expr. to
*			avoid using cast as an lvalue.
*	04-01-91   SRW	Add #pragma function for i386 _WIN32_ and _CRUISER_
*			builds
*	04-05-91   GJF	Speed up for large buffers by moving int-sized chunks
*			as much as possible.
*	08-06-91   GJF	Backed out 04-05-91 change. Pointers would have to be
*			dword-aligned for this to work on MIPS.
*       07-16-93  SRW   ALPHA Merge
*
*******************************************************************************/

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

#ifdef	_MSC_VER
#pragma function(memcpy)
#endif

/***
*memcpy - Copy source buffer to destination buffer
*
*Purpose:
*	memcpy() copies a source memory buffer to a destination memory buffer.
*	This routine does NOT recognize overlapping buffers, and thus can lead
*	to propogation.
*
*	For cases where propogation must be avoided, memmove() must be used.
*
*Entry:
*	void *dst = pointer to destination buffer
*	const void *src = pointer to source buffer
*	size_t count = number of bytes to copy
*
*Exit:
*	Returns a pointer to the destination buffer
*
*Exceptions:
*******************************************************************************/

void * _CALLTYPE1 memcpy (
	void * dst,
	const void * src,
	size_t count
	)
{
	void * ret = dst;

#if	defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_PPC)
        {
        extern void RtlMoveMemory( void *, const void *, size_t count );

        RtlMoveMemory( dst, src, count );
        }
#else
	/*
	 * copy from lower addresses to higher addresses
	 */
	while (count--) {
		*(char *)dst = *(char *)src;
		dst = (char *)dst + 1;
		src = (char *)src + 1;
	}
#endif

	return(ret);
}