summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/libntp/strdup.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ntp/libntp/strdup.c')
-rw-r--r--contrib/ntp/libntp/strdup.c29
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
OpenPOWER on IntegriCloud