xref: /netbsd-src/external/bsd/ntp/dist/libntp/strdup.c (revision ba65fde2d7fefa7d39838fa5fa855e62bd606b5e)
1 /*	$NetBSD: strdup.c,v 1.1.1.2 2012/01/31 21:23:56 kardel Exp $	*/
2 
3 #include <config.h>
4 
5 #include <string.h>
6 #include "ntp_malloc.h"
7 
8 #ifndef HAVE_STRDUP
9 
10 char *strdup(const char *s);
11 
12 char *
13 strdup(
14 	const char *s
15 	)
16 {
17 	size_t	octets;
18 	char *	cp;
19 
20 	if (s) {
21 		octets = 1 + strlen(s);
22 		cp = malloc(octets);
23 		if (NULL != cp)
24 			memcpy(cp, s, octets);
25 	else
26 		cp = NULL;
27 
28 	return(cp);
29 }
30 #else
31 int strdup_c_nonempty_compilation_unit;
32 #endif
33