Bitcoin Core
21.99.0
P2P Digital Currency
src
compat
glibc_sanity.cpp
Go to the documentation of this file.
1
// Copyright (c) 2009-2020 The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#if defined(HAVE_CONFIG_H)
6
#include <
config/bitcoin-config.h
>
7
#endif
8
9
#include <cstddef>
10
11
extern
"C"
void
*
memcpy
(
void
* a,
const
void
* b,
size_t
c);
12
void
*
memcpy_int
(
void
* a,
const
void
* b,
size_t
c)
13
{
14
return
memcpy
(a, b, c);
15
}
16
17
namespace
18
{
19
// trigger: Use the memcpy_int wrapper which calls our internal memcpy.
20
// A direct call to memcpy may be optimized away by the compiler.
21
// test: Fill an array with a sequence of integers. memcpy to a new empty array.
22
// Verify that the arrays are equal. Use an odd size to decrease the odds of
23
// the call being optimized away.
24
template
<
unsigned
int
T>
25
bool
sanity_test_memcpy()
26
{
27
unsigned
int
memcpy_test[T];
28
unsigned
int
memcpy_verify[T] = {};
29
for
(
unsigned
int
i = 0; i != T; ++i)
30
memcpy_test[i] = i;
31
32
memcpy_int
(memcpy_verify, memcpy_test,
sizeof
(memcpy_test));
33
34
for
(
unsigned
int
i = 0; i != T; ++i) {
35
if
(memcpy_verify[i] != i)
36
return
false
;
37
}
38
return
true
;
39
}
40
}
// namespace
41
42
bool
glibc_sanity_test
()
43
{
44
return
sanity_test_memcpy<1025>();
45
}
glibc_sanity_test
bool glibc_sanity_test()
Definition:
glibc_sanity.cpp:42
bitcoin-config.h
memcpy_int
void * memcpy_int(void *a, const void *b, size_t c)
Definition:
glibc_sanity.cpp:12
memcpy
void * memcpy(void *a, const void *b, size_t c)
Definition:
glibc_compat.cpp:14
Generated on Mon Mar 15 2021 20:03:35 for Bitcoin Core by
1.8.17