summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Makefile.inc4
-rw-r--r--lib/easy.c22
-rw-r--r--lib/strdup.c43
-rw-r--r--lib/strdup.h34
-rw-r--r--src/Makefile.inc3
-rw-r--r--src/main.c25
-rw-r--r--src/setup.h5
7 files changed, 105 insertions, 31 deletions
diff --git a/lib/Makefile.inc b/lib/Makefile.inc
index 7bb875847..0d3ad8cc1 100644
--- a/lib/Makefile.inc
+++ b/lib/Makefile.inc
@@ -8,7 +8,7 @@ CSOURCES = file.c timeval.c base64.c hostip.c progress.c formdata.c \
content_encoding.c share.c http_digest.c md5.c http_negotiate.c \
http_ntlm.c inet_pton.c strtoofft.c strerror.c hostares.c hostasyn.c \
hostip4.c hostip6.c hostsyn.c hostthre.c inet_ntop.c parsedate.c \
- select.c gtls.c sslgen.c tftp.c splay.c
+ select.c gtls.c sslgen.c tftp.c splay.c strdup.c
HHEADERS = arpa_telnet.h netrc.h file.h timeval.h base64.h hostip.h \
progress.h formdata.h cookie.h http.h sendf.h ftp.h url.h dict.h \
@@ -18,6 +18,6 @@ HHEADERS = arpa_telnet.h netrc.h file.h timeval.h base64.h hostip.h \
share.h md5.h http_digest.h http_negotiate.h http_ntlm.h ca-bundle.h \
inet_pton.h strtoofft.h strerror.h inet_ntop.h curlx.h memory.h \
setup.h transfer.h select.h easyif.h multiif.h parsedate.h sslgen.h \
- gtls.h tftp.h sockaddr.h splay.h
+ gtls.h tftp.h sockaddr.h splay.h strdup.h
diff --git a/lib/easy.c b/lib/easy.c
index 2784db83f..9995bcdee 100644
--- a/lib/easy.c
+++ b/lib/easy.c
@@ -80,6 +80,7 @@
#include "getinfo.h"
#include "hostip.h"
#include "share.h"
+#include "strdup.h"
#include "memory.h"
#include "progress.h"
#include "easyif.h"
@@ -182,18 +183,27 @@ static unsigned int initialized;
static long init_flags;
/*
+ * strdup (and other memory functions) is redefined in complicated
+ * ways, but at this point it must be defined as the system-supplied strdup
+ * so the callback pointer is initialized correctly.
+ */
+#if defined(_WIN32_WCE)
+#define system_strdup _strdup
+#elif !defined(HAVE_STRDUP)
+#define system_strdup curlx_strdup
+#else
+#define system_strdup strdup
+#endif
+
+/*
* If a memory-using function (like curl_getenv) is used before
* curl_global_init() is called, we need to have these pointers set already.
*/
-#ifdef _WIN32_WCE
-#define strdup _strdup
-#endif
-
curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc;
curl_free_callback Curl_cfree = (curl_free_callback)free;
curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc;
-curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)strdup;
+curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)system_strdup;
curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
/**
@@ -209,7 +219,7 @@ CURLcode curl_global_init(long flags)
Curl_cmalloc = (curl_malloc_callback)malloc;
Curl_cfree = (curl_free_callback)free;
Curl_crealloc = (curl_realloc_callback)realloc;
- Curl_cstrdup = (curl_strdup_callback)strdup;
+ Curl_cstrdup = (curl_strdup_callback)system_strdup;
Curl_ccalloc = (curl_calloc_callback)calloc;
if (flags & CURL_GLOBAL_SSL)
diff --git a/lib/strdup.c b/lib/strdup.c
new file mode 100644
index 000000000..a9ed448a8
--- /dev/null
+++ b/lib/strdup.c
@@ -0,0 +1,43 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+#include "strdup.h"
+
+#ifndef HAVE_STRDUP
+char *curlx_strdup(const char *str)
+{
+ int len;
+ char *newstr;
+
+ len = strlen(str);
+ newstr = (char *) malloc((len+1)*sizeof(char));
+ if (!newstr)
+ return (char *)NULL;
+
+ strcpy(newstr,str);
+
+ return newstr;
+
+}
+#endif
diff --git a/lib/strdup.h b/lib/strdup.h
new file mode 100644
index 000000000..3206db3cf
--- /dev/null
+++ b/lib/strdup.h
@@ -0,0 +1,34 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#ifndef _CURL_STRDUP_H
+#define _CURL_STRDUP_H
+
+#include "setup.h"
+
+#ifndef HAVE_STRDUP
+extern char *curlx_strdup(const char *str);
+#endif
+
+#endif
+
diff --git a/src/Makefile.inc b/src/Makefile.inc
index 4f2aff9a2..b6583e72c 100644
--- a/src/Makefile.inc
+++ b/src/Makefile.inc
@@ -2,7 +2,8 @@
# libcurl has sources that provide functions named curlx_* that aren't part of
# the official API, but we re-use the code here to avoid duplication.
-CURLX_ONES = $(top_srcdir)/lib/strtoofft.c $(top_srcdir)/lib/timeval.c
+CURLX_ONES = $(top_srcdir)/lib/strtoofft.c $(top_srcdir)/lib/timeval.c \
+ $(top_srcdir)/lib/strdup.c
CURL_SOURCES = main.c hugehelp.c urlglob.c writeout.c writeenv.c \
getpass.c homedir.c
diff --git a/src/main.c b/src/main.c
index 3eb11eec8..5df84d9c7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -183,25 +183,6 @@ typedef enum {
/* Send authentication (user+password) when following
* locations, even when hostname changed */
-#ifndef HAVE_STRDUP
-/* Ultrix doesn't have strdup(), so make a quick clone: */
-char *strdup(char *str)
-{
- int len;
- char *newstr;
-
- len = strlen(str);
- newstr = (char *) malloc((len+1)*sizeof(char));
- if (!newstr)
- return (char *)NULL;
-
- strcpy(newstr,str);
-
- return newstr;
-
-}
-#endif
-
#ifdef WIN32
#include <direct.h>
#define F_OK 0
@@ -1271,11 +1252,11 @@ static ParameterError add2list(struct curl_slist **list,
static int ftpfilemethod(struct Configurable *config, char *str)
{
- if(strequal("singlecwd", str))
+ if(curlx_strequal("singlecwd", str))
return CURLFTPMETHOD_SINGLECWD;
- if(strequal("nocwd", str))
+ if(curlx_strequal("nocwd", str))
return CURLFTPMETHOD_NOCWD;
- if(strequal("multicwd", str))
+ if(curlx_strequal("multicwd", str))
return CURLFTPMETHOD_MULTICWD;
warnf(config, "unrecognized ftp file method '%s', using default\n", str);
return CURLFTPMETHOD_MULTICWD;
diff --git a/src/setup.h b/src/setup.h
index d3814fef4..e911922c9 100644
--- a/src/setup.h
+++ b/src/setup.h
@@ -177,4 +177,9 @@ int fileno( FILE *stream);
#define UNPRINTABLE_CHAR '.'
#endif
+#ifndef HAVE_STRDUP
+#include "strdup.h"
+#define strdup(ptr) curlx_strdup(ptr)
+#endif
+
#endif /* __SRC_CURL_SETUP_H */