aboutsummaryrefslogtreecommitdiffstats
path: root/memdup.c
blob: a1d09599367805796f5f5f9caa1041344bc53ba9 (plain) (blame)
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
/* See LICENSE file for copyright and license details. */
#include "libsimple.h"
#ifndef TEST


void *
libsimple_memdup(const void *s, size_t n)
{
	void *ret = malloc(n ? n : (size_t)1);
	if (!ret)
		return NULL;
	return memcpy(ret, s, n);
}


#else
#include "test.h"

int
main(void)
{
	const char *s = "test";
	void *p = libsimple_memdup(s, 5);
	assert(p);
	assert(p != s);
	assert(!strcmpnul(p, s));
	memset(p, 0, 5);
	assert(!strcmpnul(s, "test"));
	free(p);
	return 0;
}

#endif