strdup.c revision 1.5
1/*	$NetBSD: strdup.c,v 1.5 2020/05/25 20:47:24 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
11char *strdup(const char *s);
12
13char *
14strdup(
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
30int strdup_c_nonempty_compilation_unit;
31#endif
32