diff options
author | delphij <delphij@FreeBSD.org> | 2015-07-15 19:21:26 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2015-07-15 19:21:26 +0000 |
commit | 2a25cee78ab1d37e7d2bc40ae675646974d99f56 (patch) | |
tree | b0302ac4be59e104f4e1e54014561a1389397192 /contrib/ntp/libntp/strdup.c | |
parent | a0741a75537b2e0514472ac3b28afc55a7846c30 (diff) | |
download | FreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.zip FreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.tar.gz |
MFC r280849,280915-280916,281015-281016,282097,282408,282415,283542,
284864,285169-285170,285435:
ntp 4.2.8p3.
Relnotes: yes
Approved by: re (?)
Diffstat (limited to 'contrib/ntp/libntp/strdup.c')
-rw-r--r-- | contrib/ntp/libntp/strdup.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/contrib/ntp/libntp/strdup.c b/contrib/ntp/libntp/strdup.c index 2e26ba7..62d5a16 100644 --- a/contrib/ntp/libntp/strdup.c +++ b/contrib/ntp/libntp/strdup.c @@ -1,8 +1,10 @@ -#include "ntp_malloc.h" +#include <config.h> -#if !HAVE_STRDUP +#include <ntp_assert.h> +#include "ntp_malloc.h" +#include <string.h> -#define NULL 0 +#ifndef HAVE_STRDUP char *strdup(const char *s); @@ -11,18 +13,17 @@ strdup( const char *s ) { - char *cp; + size_t octets; + char * cp; + + REQUIRE(s); + octets = strlen(s) + 1; + if ((cp = malloc(octets)) == NULL) + return NULL; + memcpy(cp, s, octets); - if (s) { - cp = (char *) malloc((unsigned) (strlen(s)+1)); - if (cp) { - (void) strcpy(cp, s); - } - } else { - cp = (char *) NULL; - } - return(cp); + return cp; } #else -int strdup_bs; +int strdup_c_nonempty_compilation_unit; #endif |