aboutsummaryrefslogtreecommitdiff
path: root/libutil/op_libiberty.c
blob: 0cf45d33aea439f387db8af986e3303f9b1c77b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
 * @file op_libiberty.c
 * Wrapper for libiberty - always use this instead of
 * libiberty.h
 *
 * @remark Copyright 2002 OProfile authors
 * @remark Read the file COPYING
 *
 * @author John Levon
 * @author Philippe Elie
 */

#include <string.h>

#include "op_libiberty.h"

#ifndef HAVE_XCALLOC
/* some system have a valid libiberty without xcalloc */
void * xcalloc(size_t n_elem, size_t sz)
{
	void * ptr = xmalloc(n_elem * sz);

	memset(ptr, '\0', n_elem * sz);

	return ptr;
}
#endif

#ifndef HAVE_XMEMDUP
void * xmemdup (void const * input, size_t copy_size, size_t alloc_size)
{
	void * output = xcalloc(1, alloc_size);

	memcpy(output, input, copy_size);

	return output;
}
#endif