freebsd-dev/libntp/strdup.c

30 lines
386 B
C
Raw Normal View History

#include <config.h>
2002-10-29 19:58:12 +00:00
#include <ntp_assert.h>
#include "ntp_malloc.h"
#include <string.h>
2001-08-29 14:35:15 +00:00
#ifndef HAVE_STRDUP
2001-08-29 14:35:15 +00:00
2002-10-29 19:58:12 +00:00
char *strdup(const char *s);
2001-08-29 14:35:15 +00:00
char *
strdup(
const char *s
)
{
size_t octets;
char * cp;
REQUIRE(s);
octets = strlen(s) + 1;
if ((cp = malloc(octets)) == NULL)
return NULL;
memcpy(cp, s, octets);
2001-08-29 14:35:15 +00:00
return cp;
2001-08-29 14:35:15 +00:00
}
2002-10-29 19:58:12 +00:00
#else
int strdup_c_nonempty_compilation_unit;
2002-10-29 19:58:12 +00:00
#endif