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