xref: /reactos/sdk/lib/crt/mem/memcpy.c (revision d6eebaa4)
1 #include <string.h>
2 
3 #ifdef _MSC_VER
4 #pragma function(memcpy)
5 #endif /* _MSC_VER */
6 
7 /* NOTE: This code is a duplicate of memmove implementation! */
8 void* __cdecl memcpy(void* dest, const void* src, size_t count)
9 {
10     char *char_dest = (char *)dest;
11     char *char_src = (char *)src;
12 
13     if ((char_dest <= char_src) || (char_dest >= (char_src+count)))
14     {
15         /*  non-overlapping buffers */
16         while(count > 0)
17 	{
18             *char_dest = *char_src;
19             char_dest++;
20             char_src++;
21             count--;
22 	}
23     }
24     else
25     {
26         /* overlaping buffers */
27         char_dest = (char *)dest + count - 1;
28         char_src = (char *)src + count - 1;
29 
30         while(count > 0)
31 	{
32            *char_dest = *char_src;
33            char_dest--;
34            char_src--;
35            count--;
36 	}
37     }
38 
39     return dest;
40 }
41