Deleted Added
full compact
strdup.c (302408) strdup.c (82498)
1#include <config.h>
2
1
3#include <ntp_assert.h>
4#include "ntp_malloc.h"
5#include <string.h>
2#define NULL 0
6
3
7#ifndef HAVE_STRDUP
8
9char *strdup(const char *s);
10
11char *
12strdup(
13 const char *s
14 )
15{
4char *
5strdup(
6 const char *s
7 )
8{
16 size_t octets;
17 char * cp;
9 char *cp;
18
10
19 REQUIRE(s);
20 octets = strlen(s) + 1;
21 if ((cp = malloc(octets)) == NULL)
22 return NULL;
23 memcpy(cp, s, octets);
24
25 return cp;
11 if (s) {
12 cp = (char *) malloc((unsigned) (strlen(s)+1));
13 if (cp) {
14 (void) strcpy(cp, s);
15 }
16 } else {
17 cp = (char *) NULL;
18 }
19 return(cp);
26}
20}
27#else
28int strdup_c_nonempty_compilation_unit;
29#endif