strdup.c revision 290000
1#include <config.h> 2 3#include <ntp_assert.h> 4#include "ntp_malloc.h" 5#include <string.h> 6 7#ifndef HAVE_STRDUP 8 9char *strdup(const char *s); 10 11char * 12strdup( 13 const char *s 14 ) 15{ 16 size_t octets; 17 char * cp; 18 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; 26} 27#else 28int strdup_c_nonempty_compilation_unit; 29#endif 30