1 | /* $Id: memcpy.cpp 1 1970-01-01 00:00:00Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * InnoTek Portable Runtime - CRT Strings, memcpy().
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * If you received this file as part of a commercial VirtualBox
|
---|
18 | * distribution, then only the terms of your commercial VirtualBox
|
---|
19 | * license agreement apply instead of the previous paragraph.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #include <iprt/string.h>
|
---|
27 |
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Copies a memory.
|
---|
31 | *
|
---|
32 | * @returns pvDst.
|
---|
33 | * @param pvDst Pointer to the target block.
|
---|
34 | * @param pvSrc Pointer to the source block.
|
---|
35 | * @param cb The size of the block.
|
---|
36 | */
|
---|
37 | #ifdef _MSC_VER
|
---|
38 | # if _MSC_VER >= 1400
|
---|
39 | _CRT_INSECURE_DEPRECATE_MEMORY(memcpy_s) void * __cdecl memcpy(__out_bcount_full_opt(_Size) void * pvDst, __in_bcount_opt(_Size) const void * pvSrc, __in size_t cb)
|
---|
40 | # else
|
---|
41 | void *memcpy(void *pvDst, const void *pvSrc, size_t cb)
|
---|
42 | # endif
|
---|
43 | #else
|
---|
44 | void *memcpy(void *pvDst, const void *pvSrc, size_t cb)
|
---|
45 | #endif
|
---|
46 | {
|
---|
47 | register union
|
---|
48 | {
|
---|
49 | uint8_t *pu8;
|
---|
50 | uint32_t *pu32;
|
---|
51 | void *pv;
|
---|
52 | } uTrg;
|
---|
53 | uTrg.pv = pvDst;
|
---|
54 |
|
---|
55 | register union
|
---|
56 | {
|
---|
57 | uint8_t const *pu8;
|
---|
58 | uint32_t const *pu32;
|
---|
59 | void const *pv;
|
---|
60 | } uSrc;
|
---|
61 | uSrc.pv = pvSrc;
|
---|
62 |
|
---|
63 | /* 32-bit word moves. */
|
---|
64 | register size_t c = cb >> 2;
|
---|
65 | while (c-- > 0)
|
---|
66 | *uTrg.pu32++ = *uSrc.pu32++;
|
---|
67 |
|
---|
68 | /* Remaining byte moves. */
|
---|
69 | c = cb & 3;
|
---|
70 | while (c-- > 0)
|
---|
71 | *uTrg.pu8++ = *uSrc.pu8++;
|
---|
72 |
|
---|
73 | return pvDst;
|
---|
74 | }
|
---|
75 |
|
---|