/src/core/libntech/libcompat/memdup.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | Copyright 2023 Northern.tech AS |
3 | | |
4 | | This file is part of CFEngine 3 - written and maintained by Northern.tech AS. |
5 | | |
6 | | Licensed under the Apache License, Version 2.0 (the "License"); |
7 | | you may not use this file except in compliance with the License. |
8 | | You may obtain a copy of the License at |
9 | | |
10 | | http://www.apache.org/licenses/LICENSE-2.0 |
11 | | |
12 | | Unless required by applicable law or agreed to in writing, software |
13 | | distributed under the License is distributed on an "AS IS" BASIS, |
14 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | | See the License for the specific language governing permissions and |
16 | | limitations under the License. |
17 | | |
18 | | To the extent this program is licensed as part of the Enterprise |
19 | | versions of CFEngine, the applicable Commercial Open Source License |
20 | | (COSL) may apply to this file if you as a licensee so wish it. See |
21 | | included file COSL.txt. |
22 | | */ |
23 | | |
24 | | #ifdef HAVE_CONFIG_H |
25 | | # include <config.h> |
26 | | #endif |
27 | | |
28 | | #include <stdlib.h> |
29 | | #include <string.h> |
30 | | |
31 | | #if !HAVE_DECL_MEMDUP |
32 | | void *memdup(const void *data, size_t size); |
33 | | #endif |
34 | | |
35 | | void *memdup(const void *data, size_t size) |
36 | 0 | { |
37 | 0 | void *m = malloc(size); |
38 | |
|
39 | 0 | if (m == NULL) |
40 | 0 | { |
41 | 0 | return NULL; |
42 | 0 | } |
43 | 0 | memcpy(m, data, size); |
44 | 0 | return m; |
45 | 0 | } |