/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 | | This program is free software; you can redistribute it and/or modify it |
7 | | under the terms of the GNU General Public License as published by the |
8 | | Free Software Foundation; version 3. |
9 | | |
10 | | This program is distributed in the hope that it will be useful, |
11 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | GNU General Public License for more details. |
14 | | |
15 | | You should have received a copy of the GNU General Public License |
16 | | along with this program; if not, write to the Free Software |
17 | | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
18 | | |
19 | | To the extent this program is licensed as part of the Enterprise |
20 | | versions of CFEngine, the applicable Commercial Open Source License |
21 | | (COSL) may apply to this file if you as a licensee so wish it. See |
22 | | included file COSL.txt. |
23 | | */ |
24 | | |
25 | | #ifdef HAVE_CONFIG_H |
26 | | # include <config.h> |
27 | | #endif |
28 | | |
29 | | #include <stdlib.h> |
30 | | #include <string.h> |
31 | | |
32 | | #if !HAVE_DECL_MEMDUP |
33 | | void *memdup(const void *data, size_t size); |
34 | | #endif |
35 | | |
36 | | void *memdup(const void *data, size_t size) |
37 | 0 | { |
38 | 0 | void *m = malloc(size); |
39 | |
|
40 | 0 | if (m == NULL) |
41 | 0 | { |
42 | 0 | return NULL; |
43 | 0 | } |
44 | 0 | memcpy(m, data, size); |
45 | 0 | return m; |
46 | 0 | } |