xref: /freebsd/contrib/ntp/libntp/strdup.c (revision e8643b01e6312a56d1e44a760fb4e95f0b10b54c)
1 #include <config.h>
2 
3 #include <ntp_assert.h>
4 #include "ntp_malloc.h"
5 #include <string.h>
6 
7 #ifndef HAVE_STRDUP
8 
9 char *strdup(const char *s);
10 
11 char *
12 strdup(
13 	const char *s
14 	)
15 {
16 	size_t	octets;
17 	char *	cp;
18 
19 	REQUIRE(s);
20 	octets = strlen(s) + 1;
21 	if ((cp = malloc(octets)) == NULL)
22 		return NULL;
23 	memcpy(cp, s, octets);
24 
25 	return cp;
26 }
27 #else
28 int strdup_c_nonempty_compilation_unit;
29 #endif
30