From eb886f120599b2a184db20b527db6dfdfcb7852e Mon Sep 17 00:00:00 2001 From: Yu Jiung Date: Wed, 9 Nov 2016 11:18:45 +0900 Subject: Imported Upstream version 1.11.0 Change-Id: I238c24b75a10aa902d9bc4076ed68b76b5e2a750 --- ares_strdup.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'ares_strdup.c') diff --git a/ares_strdup.c b/ares_strdup.c index 1804327..0c3dcff 100644 --- a/ares_strdup.c +++ b/ares_strdup.c @@ -17,26 +17,33 @@ #include "ares_setup.h" #include "ares_strdup.h" +#include "ares.h" +#include "ares_private.h" -#ifndef HAVE_STRDUP char *ares_strdup(const char *s1) { - size_t sz; - char * s2; +#ifdef HAVE_STRDUP + if (ares_malloc == malloc) + return strdup(s1); + else +#endif + { + size_t sz; + char * s2; - if(s1) { - sz = strlen(s1); - if(sz < (size_t)-1) { - sz++; - if(sz < ((size_t)-1) / sizeof(char)) { - s2 = malloc(sz * sizeof(char)); - if(s2) { - memcpy(s2, s1, sz * sizeof(char)); - return s2; + if(s1) { + sz = strlen(s1); + if(sz < (size_t)-1) { + sz++; + if(sz < ((size_t)-1) / sizeof(char)) { + s2 = ares_malloc(sz * sizeof(char)); + if(s2) { + memcpy(s2, s1, sz * sizeof(char)); + return s2; + } } } } + return (char *)NULL; } - return (char *)NULL; } -#endif -- cgit v1.2.3