summaryrefslogtreecommitdiff
path: root/ares_strdup.c
diff options
context:
space:
mode:
Diffstat (limited to 'ares_strdup.c')
-rw-r--r--ares_strdup.c35
1 files changed, 21 insertions, 14 deletions
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