- de-dupe lib/src strdup/memdup functions into curlx.
- introduce `CURLX_STRDUP_LOW()` for mapping `strdup()`, and to do it at
one place within the code, in `curl_setup.h`.
- tests/server: use `curlx_strdup()`. (Also to fix building without
a system `strdup()`.)
- curlx/curlx.h: shorten and tidy up.
- adjust Windows build path to not need `HAVE_STRDUP`.
- build: stop detecting `HAVE_STRDUP` on Windows.
Closes #20497
check_function_exists("setlocale" HAVE_SETLOCALE)
check_function_exists("setrlimit" HAVE_SETRLIMIT)
-if(WIN32)
- set(HAVE_STRDUP 1) # to not define local implementation. curl uses _strdup() on Windows.
-else()
+if(NOT WIN32)
check_function_exists("if_nametoindex" HAVE_IF_NAMETOINDEX) # net/if.h
check_function_exists("realpath" HAVE_REALPATH)
check_function_exists("sched_yield" HAVE_SCHED_YIELD)
CURL_CHECK_FUNC_SIGSETJMP
CURL_CHECK_FUNC_SOCKET
CURL_CHECK_FUNC_SOCKETPAIR
-CURL_CHECK_FUNC_STRDUP
CURL_CHECK_FUNC_STRERROR_R
case $host in
CURL_CHECK_FUNC_INET_PTON
CURL_CHECK_FUNC_STRCASECMP
CURL_CHECK_FUNC_STRCMPI
+ CURL_CHECK_FUNC_STRDUP
CURL_CHECK_FUNC_STRICMP
fi
curlx/multibyte.c \
curlx/nonblock.c \
curlx/strcopy.c \
+ curlx/strdup.c \
curlx/strerr.c \
curlx/strparse.c \
curlx/timediff.c \
curlx/nonblock.h \
curlx/snprintf.h \
curlx/strcopy.h \
+ curlx/strdup.h \
curlx/strerr.h \
curlx/strparse.h \
curlx/timediff.h \
socks_sspi.c \
splay.c \
strcase.c \
- strdup.c \
strequal.c \
strerror.c \
system_win32.c \
socks.h \
splay.h \
strcase.h \
- strdup.h \
strerror.h \
system_win32.h \
telnet.h \
#include "urldata.h"
#include "bufref.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
#ifdef DEBUGBUILD
#define SIGNATURE 0x5c48e9b2 /* Random pattern. */
DEBUGASSERT(len <= CURL_MAX_INPUT_LENGTH);
if(ptr) {
- cpy = Curl_memdup0(ptr, len);
+ cpy = curlx_memdup0(ptr, len);
if(!cpy)
return CURLE_OUT_OF_MEMORY;
}
#include "conncache.h"
#include "multihandle.h"
#include "rand.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
#include "system_win32.h"
#include "curlx/nonblock.h"
#include "curlx/version_win32.h"
input += strlen(if_prefix);
if(!*input)
return CURLE_BAD_FUNCTION_ARGUMENT;
- *iface = Curl_memdup0(input, len - strlen(if_prefix));
+ *iface = curlx_memdup0(input, len - strlen(if_prefix));
return *iface ? CURLE_OK : CURLE_OUT_OF_MEMORY;
}
else if(!strncmp(host_prefix, input, strlen(host_prefix))) {
input += strlen(host_prefix);
if(!*input)
return CURLE_BAD_FUNCTION_ARGUMENT;
- *host = Curl_memdup0(input, len - strlen(host_prefix));
+ *host = curlx_memdup0(input, len - strlen(host_prefix));
return *host ? CURLE_OK : CURLE_OUT_OF_MEMORY;
}
else if(!strncmp(if_host_prefix, input, strlen(if_host_prefix))) {
host_part = memchr(input, '!', len);
if(!host_part || !*(host_part + 1))
return CURLE_BAD_FUNCTION_ARGUMENT;
- *iface = Curl_memdup0(input, host_part - input);
+ *iface = curlx_memdup0(input, host_part - input);
if(!*iface)
return CURLE_OUT_OF_MEMORY;
++host_part;
- *host = Curl_memdup0(host_part, len - (host_part - input));
+ *host = curlx_memdup0(host_part, len - (host_part - input));
if(!*host) {
curlx_free(*iface);
*iface = NULL;
if(!*input)
return CURLE_BAD_FUNCTION_ARGUMENT;
- *dev = Curl_memdup0(input, len);
+ *dev = curlx_memdup0(input, len);
return *dev ? CURLE_OK : CURLE_OUT_OF_MEMORY;
}
/* Define if you have the socket function. */
#define HAVE_SOCKET 1
-/* Define if you have the strdup function. */
-#define HAVE_STRDUP 1
-
/* Define if you have the utime function. */
#define HAVE_UTIME 1
#include "curl_get_line.h"
#include "curl_memrchr.h"
#include "parsedate.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
#include "llist.h"
#include "bufref.h"
#include "curlx/strparse.h"
if(len > 1 && cookie_path[len - 1] == '/')
len--;
- return Curl_memdup0(cookie_path, len);
+ return curlx_memdup0(cookie_path, len);
}
/*
len++;
newstr = "";
}
- *str = Curl_memdup0(newstr, len);
+ *str = curlx_memdup0(newstr, len);
if(!*str)
return CURLE_OUT_OF_MEMORY;
return CURLE_OK;
ptr++;
len--;
}
- co->domain = Curl_memdup0(ptr, len);
+ co->domain = curlx_memdup0(ptr, len);
if(!co->domain)
return CURLE_OUT_OF_MEMORY;
break;
return CURLE_OK;
break;
case 5:
- co->name = Curl_memdup0(ptr, len);
+ co->name = curlx_memdup0(ptr, len);
if(!co->name)
return CURLE_OUT_OF_MEMORY;
else {
}
break;
case 6:
- co->value = Curl_memdup0(ptr, len);
+ co->value = curlx_memdup0(ptr, len);
if(!co->value)
return CURLE_OUT_OF_MEMORY;
break;
goto fail;
/* clone the stack struct into heap */
- co = Curl_memdup(&comem, sizeof(comem));
+ co = curlx_memdup(&comem, sizeof(comem));
if(!co) {
co = &comem;
result = CURLE_OUT_OF_MEMORY;
/* Allocator macros */
+#ifdef _WIN32
+#define CURLX_STRDUP_LOW _strdup
+#elif !defined(HAVE_STRDUP)
+#define CURLX_STRDUP_LOW curlx_strdup_low
+#else
+#define CURLX_STRDUP_LOW strdup
+#endif
+
#ifdef CURL_MEMDEBUG
#define curlx_strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__)
#define curlx_realloc Curl_crealloc
#define curlx_free Curl_cfree
#else /* !BUILDING_LIBCURL */
-#ifdef _WIN32
-#define curlx_strdup _strdup
-#else
-#define curlx_strdup strdup
-#endif
+#define curlx_strdup CURLX_STRDUP_LOW
#define curlx_malloc malloc
#define curlx_calloc calloc
#define curlx_realloc realloc
#ifdef _WIN32
#ifdef UNICODE
-#define curlx_tcsdup Curl_wcsdup
+#define curlx_tcsdup curlx_wcsdup
#else
#define curlx_tcsdup curlx_strdup
#endif
#ifdef USE_WINDOWS_SSPI
#include "curl_sspi.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
#include "curlx/multibyte.h"
/* Pointer to SSPI dispatch table */
* be.
*/
-#include "basename.h"
-/* for curlx_basename() function */
-
-#include "binmode.h"
-/* "binmode.h" provides macro CURLX_SET_BINMODE() */
-
-#include "nonblock.h"
-/* "nonblock.h" provides curlx_nonblock() */
-
-#include "multibyte.h"
-/* "multibyte.h" provides these functions and macros:
-
- curlx_convert_UTF8_to_wchar()
- curlx_convert_wchar_to_UTF8()
- curlx_convert_UTF8_to_tchar()
- curlx_convert_tchar_to_UTF8()
-*/
-
-#include "version_win32.h"
-/* provides curlx_verify_windows_version() */
-
-#include "strerr.h"
-/* The curlx_strerror() function */
-
-#include "strparse.h"
-/* The curlx_str_* parsing functions */
-
-#include "strcopy.h"
-/* curlx_strcopy */
-
-#include "dynbuf.h"
-/* The curlx_dyn_* functions */
-
-#include "fopen.h"
-/* The curlx_f* functions */
-
-#include "base64.h"
-#include "timeval.h"
-#include "timediff.h"
-
-#include "wait.h"
-/* for curlx_wait_ms */
-
-#include "winapi.h"
-/* for curlx_winapi_strerror */
-
-#include "inet_pton.h"
-/* for curlx_inet_pton */
-
-#include "inet_ntop.h"
-/* for curlx_inet_ntop */
+#include "base64.h" /* for curlx_base64* */
+#include "basename.h" /* for curlx_basename() */
+#include "binmode.h" /* for macro CURLX_SET_BINMODE() */
+#include "dynbuf.h" /* for curlx_dyn_*() */
+#include "fopen.h" /* for curlx_f*() */
+#include "inet_ntop.h" /* for curlx_inet_ntop() */
+#include "inet_pton.h" /* for curlx_inet_pton() */
+#include "multibyte.h" /* for curlx_convert_*() */
+#include "nonblock.h" /* for curlx_nonblock() */
+#include "strcopy.h" /* for curlx_strcopy() */
+#include "strdup.h" /* for curlx_memdup*() and curlx_tcsdup() */
+#include "strerr.h" /* for curlx_strerror() */
+#include "strparse.h" /* for curlx_str_* parsing functions */
+#include "timediff.h" /* for timediff_t type and related functions */
+#include "timeval.h" /* for curlx_now type and related functions */
+#include "version_win32.h" /* for curlx_verify_windows_version() */
+#include "wait.h" /* for curlx_wait_ms() */
+#include "winapi.h" /* for curlx_winapi_strerror() */
#endif /* HEADER_CURL_CURLX_H */
}
if(a != s->allc) {
- /* this logic is not using Curl_saferealloc() to make the tool not have to
+ /* this logic is not using curlx_saferealloc() to make the tool not have to
include that as well when it uses this code */
void *p = curlx_realloc(s->bufr, a);
if(!p) {
* SPDX-License-Identifier: curl
*
***************************************************************************/
-#include "curl_setup.h"
+#include "../curl_setup.h"
#ifdef _WIN32
#include <wchar.h>
#include "strdup.h"
-#ifndef HAVE_STRDUP
-char *Curl_strdup(const char *str)
-{
- size_t len;
- char *newstr;
-
- if(!str)
- return NULL;
-
- len = strlen(str) + 1;
-
- newstr = curlx_malloc(len);
- if(!newstr)
- return NULL;
-
- memcpy(newstr, str, len);
- return newstr;
-}
-#endif
-
#ifdef _WIN32
/***************************************************************************
*
- * Curl_wcsdup(source)
+ * curlx_wcsdup(source)
*
* Copies the 'source' wchar string to a newly allocated buffer (that is
- * returned).
+ * returned). Used by macro curlx_tcsdup().
*
* Returns the new pointer or NULL on failure.
*
***************************************************************************/
-wchar_t *Curl_wcsdup(const wchar_t *src)
+wchar_t *curlx_wcsdup(const wchar_t *src)
{
size_t length = wcslen(src);
if(length > (SIZE_MAX / sizeof(wchar_t)) - 1)
return (wchar_t *)NULL; /* integer overflow */
- return (wchar_t *)Curl_memdup(src, (length + 1) * sizeof(wchar_t));
+ return (wchar_t *)curlx_memdup(src, (length + 1) * sizeof(wchar_t));
+}
+#elif !defined(HAVE_STRDUP)
+char *curlx_strdup_low(const char *str)
+{
+ size_t len;
+ char *newstr;
+
+ if(!str)
+ return NULL;
+
+ len = strlen(str) + 1;
+
+ newstr = curlx_malloc(len);
+ if(!newstr)
+ return NULL;
+
+ memcpy(newstr, str, len);
+ return newstr;
}
#endif
/***************************************************************************
*
- * Curl_memdup(source, length)
+ * curlx_memdup(source, length)
*
* Copies the 'source' data to a newly allocated buffer (that is
* returned). Copies 'length' bytes.
* Returns the new pointer or NULL on failure.
*
***************************************************************************/
-void *Curl_memdup(const void *src, size_t length)
+void *curlx_memdup(const void *src, size_t length)
{
void *buffer = curlx_malloc(length);
if(!buffer)
/***************************************************************************
*
- * Curl_memdup0(source, length)
+ * curlx_memdup0(source, length)
*
* Copies the 'source' string to a newly allocated buffer (that is returned).
* Copies 'length' bytes then adds a null-terminator.
* Returns the new pointer or NULL on failure.
*
***************************************************************************/
-void *Curl_memdup0(const char *src, size_t length)
+void *curlx_memdup0(const char *src, size_t length)
{
char *buf = (length < SIZE_MAX) ? curlx_malloc(length + 1) : NULL;
if(!buf)
/***************************************************************************
*
- * Curl_saferealloc(ptr, size)
+ * curlx_saferealloc(ptr, size)
*
* Does a normal curlx_realloc(), but will free the data pointer if the realloc
* fails. If 'size' is non-zero, it will free the data and return a failure.
* Returns the new pointer or NULL on failure.
*
***************************************************************************/
-void *Curl_saferealloc(void *ptr, size_t size)
+void *curlx_saferealloc(void *ptr, size_t size)
{
void *datap = curlx_realloc(ptr, size);
if(size && !datap)
-#ifndef HEADER_CURL_STRDUP_H
-#define HEADER_CURL_STRDUP_H
+#ifndef HEADER_CURLX_STRDUP_H
+#define HEADER_CURLX_STRDUP_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* SPDX-License-Identifier: curl
*
***************************************************************************/
-#include "curl_setup.h"
+#include "../curl_setup.h"
-#ifndef HAVE_STRDUP
-char *Curl_strdup(const char *str);
-#endif
#ifdef _WIN32
-wchar_t *Curl_wcsdup(const wchar_t *src);
+wchar_t *curlx_wcsdup(const wchar_t *src); /* for curlx_tcsdup() */
+#elif !defined(HAVE_STRDUP)
+char *curlx_strdup_low(const char *str);
#endif
-void *Curl_memdup(const void *src, size_t buffer_length);
-void *Curl_saferealloc(void *ptr, size_t size);
-void *Curl_memdup0(const char *src, size_t length);
-#endif /* HEADER_CURL_STRDUP_H */
+void *curlx_memdup(const void *src, size_t buffer_length);
+void *curlx_memdup0(const char *src, size_t length);
+void *curlx_saferealloc(void *ptr, size_t size);
+#endif /* HEADER_CURLX_STRDUP_H */
#include "multiif.h"
#include "url.h"
#include "connect.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
#include "curlx/dynbuf.h"
#include "escape.h"
#include "urlapi-int.h"
/* silently ignore RRs over the limit */
if(d->numhttps_rrs < DOH_MAX_HTTPS) {
struct dohhttps_rr *h = &d->https_rrs[d->numhttps_rrs];
- h->val = Curl_memdup(&doh[index], len);
+ h->val = curlx_memdup(&doh[index], len);
if(!h->val)
return DOH_OUT_OF_MEM;
h->len = len;
#include "url.h"
#include "getinfo.h"
#include "hostip.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
#include "easyif.h"
#include "multiif.h"
#include "multi_ev.h"
#endif
-/*
- * 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.
- */
-#ifdef _WIN32
-#define system_strdup _strdup
-#elif defined(HAVE_STRDUP)
-#define system_strdup strdup
-#else
-#define system_strdup Curl_strdup
-#endif
-
#if defined(_MSC_VER) && defined(_DLL)
# pragma warning(push)
# pragma warning(disable:4232) /* MSVC extension, dllimport identity */
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)system_strdup;
+curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)CURLX_STRDUP_LOW;
curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
#if defined(_MSC_VER) && defined(_DLL)
Curl_cmalloc = (curl_malloc_callback)malloc;
Curl_cfree = (curl_free_callback)free;
Curl_crealloc = (curl_realloc_callback)realloc;
- Curl_cstrdup = (curl_strdup_callback)system_strdup;
+ Curl_cstrdup = (curl_strdup_callback)CURLX_STRDUP_LOW;
Curl_ccalloc = (curl_calloc_callback)calloc;
}
if(src->set.postfieldsize == -1)
dst->set.str[i] = curlx_strdup(src->set.str[i]);
else
- /* postfieldsize is curl_off_t, Curl_memdup() takes a size_t ... */
- dst->set.str[i] = Curl_memdup(src->set.str[i],
- curlx_sotouz(src->set.postfieldsize));
+ /* postfieldsize is curl_off_t, curlx_memdup() takes a size_t ... */
+ dst->set.str[i] = curlx_memdup(src->set.str[i],
+ curlx_sotouz(src->set.postfieldsize));
if(!dst->set.str[i])
return CURLE_OUT_OF_MEMORY;
/* point to the new copy */
#include "urldata.h" /* for struct Curl_easy */
#include "mime.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
#include "bufref.h"
#include "curlx/fopen.h"
if(!name || !len)
return curl_mime_name(part, name);
- zname = Curl_memdup0(name, len);
+ zname = curlx_memdup0(name, len);
if(!zname)
return CURLE_OUT_OF_MEMORY;
res = curl_mime_name(part, zname);
#include "multiif.h"
#include "url.h"
#include "http_proxy.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
#include "curlx/strerr.h"
#include "curlx/strparse.h"
ptr++;
for(start = ptr; *ptr && *ptr != ' '; ptr++)
;
- os = Curl_memdup0(start, ptr - start);
+ os = curlx_memdup0(start, ptr - start);
if(!os)
return CURLE_OUT_OF_MEMORY;
else
/* file is url-decoded */
pathLen -= ftpc->file ? strlen(ftpc->file) : 0;
- ftpc->prevpath = Curl_memdup0(rawPath, pathLen);
+ ftpc->prevpath = curlx_memdup0(rawPath, pathLen);
}
else
ftpc->prevpath = NULL; /* no path */
#include "http2.h"
#include "cfilters.h"
#include "connect.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
#include "altsvc.h"
#include "hsts.h"
#include "rtsp.h"
curlx_str_untilnl(&header, &out, MAX_HTTP_RESP_HEADER_SIZE);
curlx_str_trimblanks(&out);
- *valp = Curl_memdup0(curlx_str(&out), curlx_strlen(&out));
+ *valp = curlx_memdup0(curlx_str(&out), curlx_strlen(&out));
if(*valp)
return CURLE_OK;
return CURLE_OUT_OF_MEMORY;
!curlx_str_single(&header, ':')) {
curlx_str_untilnl(&header, &out, MAX_HTTP_RESP_HEADER_SIZE);
curlx_str_trimblanks(&out);
- return Curl_memdup0(curlx_str(&out), curlx_strlen(&out));
+ return curlx_memdup0(curlx_str(&out), curlx_strlen(&out));
}
/* bad input, should never happen */
DEBUGASSERT(0);
#pragma GCC diagnostic pop
#endif
if(scheme) {
- req->scheme = Curl_memdup0(scheme, s_len);
+ req->scheme = curlx_memdup0(scheme, s_len);
if(!req->scheme)
goto out;
}
if(authority) {
- req->authority = Curl_memdup0(authority, a_len);
+ req->authority = curlx_memdup0(authority, a_len);
if(!req->authority)
goto out;
}
if(path) {
- req->path = Curl_memdup0(path, p_len);
+ req->path = curlx_memdup0(path, p_len);
if(!req->path)
goto out;
}
#include "urldata.h"
#include "strcase.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
#include "http_aws_sigv4.h"
#include "curl_sha256.h"
#include "transfer.h"
if(data->state.aptr.host) {
/* remove /r/n as the separator for canonical request must be '\n' */
size_t pos = strcspn(data->state.aptr.host, "\n\r");
- fullhost = Curl_memdup0(data->state.aptr.host, pos);
+ fullhost = curlx_memdup0(data->state.aptr.host, pos);
}
else
fullhost = curl_maprintf("host:%s", hostname);
#include "httpsrr.h"
#include "connect.h"
#include "curl_trc.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
static CURLcode httpsrr_decode_alpn(const uint8_t *cp, size_t len,
unsigned char *alpns)
if(!vlen || (vlen & 3)) /* the size must be 4-byte aligned */
return CURLE_BAD_FUNCTION_ARGUMENT;
curlx_free(hi->ipv4hints);
- hi->ipv4hints = Curl_memdup(val, vlen);
+ hi->ipv4hints = curlx_memdup(val, vlen);
if(!hi->ipv4hints)
return CURLE_OUT_OF_MEMORY;
hi->ipv4hints_len = vlen;
if(!vlen)
return CURLE_BAD_FUNCTION_ARGUMENT;
curlx_free(hi->echconfiglist);
- hi->echconfiglist = Curl_memdup(val, vlen);
+ hi->echconfiglist = curlx_memdup(val, vlen);
if(!hi->echconfiglist)
return CURLE_OUT_OF_MEMORY;
hi->echconfiglist_len = vlen;
if(!vlen || (vlen & 15)) /* the size must be 16-byte aligned */
return CURLE_BAD_FUNCTION_ARGUMENT;
curlx_free(hi->ipv6hints);
- hi->ipv6hints = Curl_memdup(val, vlen);
+ hi->ipv6hints = curlx_memdup(val, vlen);
if(!hi->ipv6hints)
return CURLE_OUT_OF_MEMORY;
hi->ipv6hints_len = vlen;
struct Curl_https_rrinfo *
Curl_httpsrr_dup_move(struct Curl_https_rrinfo *rrinfo)
{
- struct Curl_https_rrinfo *dup = Curl_memdup(rrinfo, sizeof(*rrinfo));
+ struct Curl_https_rrinfo *dup = curlx_memdup(rrinfo, sizeof(*rrinfo));
if(dup)
memset(rrinfo, 0, sizeof(*rrinfo));
return dup;
#include "sendf.h"
#include "curl_trc.h"
#include "transfer.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
#include "curlx/basename.h"
#include "curlx/strcopy.h"
#include "curlx/fopen.h"
if(datasize == CURL_ZERO_TERMINATED)
datasize = strlen(ptr);
- part->data = Curl_memdup0(ptr, datasize);
+ part->data = curlx_memdup0(ptr, datasize);
if(!part->data)
return CURLE_OUT_OF_MEMORY;
#include "bufref.h"
#include "curl_sasl.h"
#include "curl_md5.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
/* Authentication type flags */
#define POP3_TYPE_CLEARTEXT (1 << 0)
therefore do not use APOP authentication. */
if(at) {
/* dupe the timestamp */
- pop3c->apoptimestamp = Curl_memdup0(lt, timestamplen);
+ pop3c->apoptimestamp = curlx_memdup0(lt, timestamplen);
if(!pop3c->apoptimestamp)
return CURLE_OUT_OF_MEMORY;
/* Store the APOP capability */
#include "select.h"
#include "connect.h"
#include "cfilters.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
#include "bufref.h"
#include "curlx/strparse.h"
*/
/* Copy the id substring into a new buffer */
- data->set.str[STRING_RTSP_SESSION_ID] = Curl_memdup0(start, idlen);
+ data->set.str[STRING_RTSP_SESSION_ID] = curlx_memdup0(start, idlen);
if(!data->set.str[STRING_RTSP_SESSION_ID])
return CURLE_OUT_OF_MEMORY;
}
#include "altsvc.h"
#include "hsts.h"
#include "tftp.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
#include "escape.h"
#include "bufref.h"
mark that postfields is used rather than read function or form
data.
*/
- char *p = Curl_memdup0(ptr, pflen);
+ char *p = curlx_memdup0(ptr, pflen);
if(!p)
return CURLE_OUT_OF_MEMORY;
else {
#include "connect.h"
#include "curlx/nonblock.h"
#include "socks.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
#if defined(__GNUC__) && defined(__APPLE__)
#pragma GCC diagnostic push
/* prepare service name */
if(strchr(serviceptr, '/')) {
service.length = serviceptr_length;
- service.value = Curl_memdup(serviceptr, service.length);
+ service.value = curlx_memdup(serviceptr, service.length);
if(!service.value)
return CURLE_OUT_OF_MEMORY;
}
else {
gss_send_token.length = 1;
- gss_send_token.value = Curl_memdup(&gss_enc, gss_send_token.length);
+ gss_send_token.value = curlx_memdup(&gss_enc, gss_send_token.length);
if(!gss_send_token.value) {
Curl_gss_delete_sec_context(&gss_status, &gss_context, NULL);
return CURLE_OUT_OF_MEMORY;
#include "http_proxy.h"
#include "conncache.h"
#include "multihandle.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
#include "setopt.h"
#include "altsvc.h"
#include "curlx/dynbuf.h"
(size_t)(login + len - osep)) - 1 : 0);
/* Clone the user portion buffer, which can be zero length */
- ubuf = Curl_memdup0(login, ulen);
+ ubuf = curlx_memdup0(login, ulen);
if(!ubuf)
goto error;
/* Clone the password portion buffer */
if(psep) {
- pbuf = Curl_memdup0(&psep[1], plen);
+ pbuf = curlx_memdup0(&psep[1], plen);
if(!pbuf)
goto error;
}
if(optionsp) {
char *obuf = NULL;
if(olen) {
- obuf = Curl_memdup0(&osep[1], olen);
+ obuf = curlx_memdup0(&osep[1], olen);
if(!obuf)
goto error;
}
#include "escape.h"
#include "curlx/inet_pton.h"
#include "curlx/inet_ntop.h"
-#include "strdup.h"
+#include "curlx/strdup.h"
#include "idn.h"
#include "curlx/strparse.h"
#include "curl_memrchr.h"
u->fragment = curlx_dyn_ptr(&enc);
}
else {
- u->fragment = Curl_memdup0(fragment + 1, fraglen - 1);
+ u->fragment = curlx_memdup0(fragment + 1, fraglen - 1);
if(!u->fragment)
return CURLUE_OUT_OF_MEMORY;
}
u->query = curlx_dyn_ptr(&enc);
}
else {
- u->query = Curl_memdup0(query + 1, qlen - 1);
+ u->query = curlx_memdup0(query + 1, qlen - 1);
if(!u->query)
return CURLUE_OUT_OF_MEMORY;
}
}
else {
if(!u->path) {
- u->path = Curl_memdup0(path, pathlen);
+ u->path = curlx_memdup0(path, pathlen);
if(!u->path)
return CURLUE_OUT_OF_MEMORY;
path = u->path;
bool urlencode = (flags & CURLU_URLENCODE) ? 1 : 0;
bool punycode = (flags & CURLU_PUNYCODE) && (what == CURLUPART_HOST);
bool depunyfy = (flags & CURLU_PUNY2IDN) && (what == CURLUPART_HOST);
- char *part = Curl_memdup0(ptr, partlen);
+ char *part = curlx_memdup0(ptr, partlen);
*partp = NULL;
if(!part)
return CURLUE_OUT_OF_MEMORY;
#include "digest.h"
#include "../curlx/multibyte.h"
#include "../curl_trc.h"
-#include "../strdup.h"
+#include "../curlx/strdup.h"
#include "../strcase.h"
#include "../strerror.h"
}
/* Store the challenge for use later */
- digest->input_token = (BYTE *)Curl_memdup(chlg, chlglen + 1);
+ digest->input_token = (BYTE *)curlx_memdup(chlg, chlglen + 1);
if(!digest->input_token)
return CURLE_OUT_OF_MEMORY;
Curl_sspi_free_identity(p_identity);
}
- resp = Curl_memdup0((const char *)output_token, output_token_len);
+ resp = curlx_memdup0((const char *)output_token, output_token_len);
curlx_free(output_token);
if(!resp) {
return CURLE_OUT_OF_MEMORY;
#include "../curl_trc.h"
#include "../curl_ntlm_core.h"
#include "../rand.h"
-#include "../strdup.h"
+#include "../curlx/strdup.h"
#include "../curl_endian.h"
/* NTLM buffer fixed size, large enough for long user + host + domain */
}
curlx_free(ntlm->target_info); /* replace any previous data */
- ntlm->target_info = Curl_memdup(&type2[target_info_offset],
- target_info_len);
+ ntlm->target_info = curlx_memdup(&type2[target_info_offset],
+ target_info_len);
if(!ntlm->target_info)
return CURLE_OUT_OF_MEMORY;
}
#include "vauth.h"
#include "../curl_ntlm_core.h"
#include "../curl_trc.h"
-#include "../strdup.h"
+#include "../curlx/strdup.h"
/*
* Curl_auth_is_ntlm_supported()
}
/* Store the challenge for later use */
- ntlm->input_token = Curl_memdup0(Curl_bufref_ptr(type2),
- Curl_bufref_len(type2));
+ ntlm->input_token = curlx_memdup0(Curl_bufref_ptr(type2),
+ Curl_bufref_len(type2));
if(!ntlm->input_token)
return CURLE_OUT_OF_MEMORY;
ntlm->input_token_len = Curl_bufref_len(type2);
#include "../parsedate.h"
#include "../connect.h" /* for the connect timeout */
#include "../progress.h"
-#include "../strdup.h"
+#include "../curlx/strdup.h"
#include "../curlx/fopen.h"
#include "x509asn1.h"
"and store in cache", sdata_len, alpn ? alpn : "-",
earlydata_max);
if(quic_tp && quic_tp_len) {
- qtp_clone = Curl_memdup0((char *)quic_tp, quic_tp_len);
+ qtp_clone = curlx_memdup0((char *)quic_tp, quic_tp_len);
if(!qtp_clone) {
curlx_free(sdata);
return CURLE_OUT_OF_MEMORY;
#include "vtls_scache.h"
#include "x509asn1.h"
#include "../connect.h" /* for the connect timeout */
-#include "../strdup.h"
+#include "../curlx/strdup.h"
#include "../curl_sha256.h"
/* ALPN for http2 */
provided the exact length). The function accepts PEM or DER
formats, but we cannot assume if the user passed in a PEM
format cert that it is null-terminated. */
- unsigned char *newblob = Curl_memdup0(ca_info_blob->data,
- ca_info_blob->len);
+ unsigned char *newblob = curlx_memdup0(ca_info_blob->data,
+ ca_info_blob->len);
if(!newblob)
return CURLE_OUT_OF_MEMORY;
provided the exact length). The function accepts PEM or DER
formats, but we cannot assume if the user passed in a PEM
format cert that it is null-terminated. */
- unsigned char *newblob = Curl_memdup0(ssl_cert_blob->data,
- ssl_cert_blob->len);
+ unsigned char *newblob = curlx_memdup0(ssl_cert_blob->data,
+ ssl_cert_blob->len);
if(!newblob)
return CURLE_OUT_OF_MEMORY;
ret = mbedtls_x509_crt_parse(&backend->clicert, newblob,
#include "../curlx/strerr.h"
#include "../curlx/strparse.h"
#include "../curlx/strcopy.h"
-#include "../strdup.h"
+#include "../curlx/strdup.h"
#include "apple.h"
#include <openssl/rand.h>
earlydata_max = SSL_SESSION_get_max_early_data(session);
#endif
if(quic_tp && quic_tp_len) {
- qtp_clone = Curl_memdup0((char *)quic_tp, quic_tp_len);
+ qtp_clone = curlx_memdup0((char *)quic_tp, quic_tp_len);
if(!qtp_clone) {
result = CURLE_OUT_OF_MEMORY;
goto out;
#include "vtls_scache.h"
#include "../curl_trc.h"
#include "../connect.h" /* for the connect timeout */
-#include "../strdup.h"
+#include "../curlx/strdup.h"
#include "../strerror.h"
#include "../select.h" /* for the socket readiness */
#include "../curlx/fopen.h"
#include "../connect.h"
#include "../select.h"
#include "../setopt.h"
-#include "../strdup.h"
+#include "../curlx/strdup.h"
#include "../curlx/strcopy.h"
#ifdef USE_APPLE_SECTRUST
result = CURLE_SSL_CONNECT_ERROR;
goto out;
}
- connssl->negotiated.alpn = Curl_memdup0((const char *)proto, proto_len);
+ connssl->negotiated.alpn = curlx_memdup0((const char *)proto, proto_len);
if(!connssl->negotiated.alpn)
return CURLE_OUT_OF_MEMORY;
}
#include "../curl_trc.h"
#include "vtls_scache.h"
#include "vtls_spack.h"
-#include "../strdup.h"
+#include "../curlx/strdup.h"
#ifndef UINT16_MAX
#define UINT16_MAX 0xffff
return r;
if(end - *src < slen)
return CURLE_READ_ERROR;
- *val = Curl_memdup0((const char *)(*src), slen);
+ *val = curlx_memdup0((const char *)(*src), slen);
*src += slen;
return *val ? CURLE_OK : CURLE_OUT_OF_MEMORY;
}
return r;
if(end - *src < data_len)
return CURLE_READ_ERROR;
- *val = Curl_memdup0((const char *)(*src), data_len);
+ *val = curlx_memdup0((const char *)(*src), data_len);
*val_len = data_len;
*src += data_len;
return *val ? CURLE_OK : CURLE_OUT_OF_MEMORY;
#include "keylog.h"
#include "../connect.h" /* for the connect timeout */
#include "../progress.h"
-#include "../strdup.h"
+#include "../curlx/strdup.h"
#include "../curlx/strcopy.h"
#include "x509asn1.h"
goto out;
}
if(quic_tp && quic_tp_len) {
- qtp_clone = Curl_memdup0((char *)quic_tp, quic_tp_len);
+ qtp_clone = curlx_memdup0((char *)quic_tp, quic_tp_len);
if(!qtp_clone) {
curlx_free(sdata);
return CURLE_OUT_OF_MEMORY;
../lib/curlx/multibyte.c \
../lib/curlx/nonblock.c \
../lib/curlx/strcopy.c \
+ ../lib/curlx/strdup.c \
../lib/curlx/strerr.c \
../lib/curlx/strparse.c \
../lib/curlx/timediff.c \
../lib/curlx/nonblock.h \
../lib/curlx/snprintf.h \
../lib/curlx/strcopy.h \
+ ../lib/curlx/strdup.h \
../lib/curlx/strerr.h \
../lib/curlx/strparse.h \
../lib/curlx/timediff.h \
tool_setopt.c \
tool_ssls.c \
tool_stderr.c \
- tool_strdup.c \
tool_urlglob.c \
tool_util.c \
tool_vms.c \
tool_setup.h \
tool_ssls.h \
tool_stderr.h \
- tool_strdup.h \
tool_urlglob.h \
tool_util.h \
tool_version.h \
#include "tool_cb_wrt.h"
#include "tool_operate.h"
#include "tool_libinfo.h"
-#include "tool_strdup.h"
#ifdef _WIN32
#define BOLD "\x1b[1m"
goto locout;
/* Create a null-terminated and whitespace-stripped copy of Location: */
- copyloc = memdup0(loc, llen);
+ copyloc = curlx_memdup0(loc, llen);
if(!copyloc)
goto locout;
char *p;
char *q;
- copy = memdup0(ptr, len);
+ copy = curlx_memdup0(ptr, len);
if(!copy)
return NULL;
#include "tool_main.h"
#include "tool_stderr.h"
#include "tool_help.h"
-#include "tool_strdup.h"
#include "var.h"
#define ALLOW_BLANK TRUE
if(!allowblank && !val[0])
return PARAM_BLANK_STRING;
- *str = memdup0(val, len);
+ *str = curlx_memdup0(val, len);
if(!*str)
return PARAM_NO_MEM;
/* define what to use for unprintable characters */
#define UNPRINTABLE_CHAR '.'
-#ifndef HAVE_STRDUP
-#include "tool_strdup.h"
-#undef Curl_strdup
-#define Curl_strdup tool_strdup
-#endif
-
#ifndef tool_nop_stmt
#define tool_nop_stmt do {} while(0)
#endif
+++ /dev/null
-/***************************************************************************
- * _ _ ____ _
- * Project ___| | | | _ \| |
- * / __| | | | |_) | |
- * | (__| |_| | _ <| |___
- * \___|\___/|_| \_\_____|
- *
- * Copyright (C) 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 https://curl.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.
- *
- * SPDX-License-Identifier: curl
- *
- ***************************************************************************/
-#include "tool_strdup.h"
-
-#ifndef HAVE_STRDUP
-char *tool_strdup(const char *str)
-{
- size_t len;
- char *newstr;
-
- if(!str)
- return (char *)NULL;
-
- len = strlen(str) + 1;
-
- newstr = curlx_malloc(len);
- if(!newstr)
- return (char *)NULL;
-
- memcpy(newstr, str, len);
- return newstr;
-}
-#endif
-
-char *memdup0(const char *data, size_t len)
-{
- char *p = curlx_malloc(len + 1);
- if(!p)
- return NULL;
- if(len)
- memcpy(p, data, len);
- p[len] = 0;
- return p;
-}
+++ /dev/null
-#ifndef HEADER_TOOL_STRDUP_H
-#define HEADER_TOOL_STRDUP_H
-/***************************************************************************
- * _ _ ____ _
- * Project ___| | | | _ \| |
- * / __| | | | |_) | |
- * | (__| |_| | _ <| |___
- * \___|\___/|_| \_\_____|
- *
- * Copyright (C) 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 https://curl.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.
- *
- * SPDX-License-Identifier: curl
- *
- ***************************************************************************/
-#include "tool_setup.h"
-
-#ifndef HAVE_STRDUP
-extern char *tool_strdup(const char *str);
-#endif
-char *memdup0(const char *data, size_t len);
-
-#endif /* HEADER_TOOL_STRDUP_H */
#include "tool_doswin.h"
#include "tool_urlglob.h"
#include "tool_vms.h"
-#include "tool_strdup.h"
static CURLcode globerror(struct URLGlob *glob, const char *err,
size_t pos, CURLcode error)
if(!pat->c.set.elem)
return globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY);
- pat->c.set.elem[0] = memdup0(fixed, len);
+ pat->c.set.elem[0] = curlx_memdup0(fixed, len);
if(!pat->c.set.elem[0]) {
tool_safefree(pat->c.set.elem);
return globerror(glob, NULL, 0, CURLE_OUT_OF_MEMORY);
#include "tool_msgs.h"
#include "tool_paramhlp.h"
#include "tool_writeout_json.h"
-#include "tool_strdup.h"
#include "var.h"
#define MAX_EXPAND_CONTENT 10000000
curlx_free(c);
clen = curlx_dyn_len(out);
- c = memdup0(curlx_dyn_ptr(out), clen);
+ c = curlx_memdup0(curlx_dyn_ptr(out), clen);
if(!c) {
err = PARAM_NO_MEM;
break;
memcpy(p->name, name, nlen);
/* the null termination byte is already present from above */
- p->content = contalloc ? content : memdup0(content, clen);
+ p->content = contalloc ? content : curlx_memdup0(content, clen);
if(p->content) {
p->clen = clen;
static char *custom_strdup(const char *ptr)
{
seen++;
-#ifdef _WIN32
- return _strdup(ptr);
-#else
- /* !checksrc! disable BANNEDFUNC 1 */
- return strdup(ptr);
-#endif
+ return CURLX_STRDUP_LOW(ptr);
}
static void *custom_realloc(void *ptr, size_t size)
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;
-#ifdef _WIN32
-curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)_strdup;
-#else
-curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)strdup;
-#endif
+curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)CURLX_STRDUP_LOW;
curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
#if defined(_MSC_VER) && defined(_DLL)
allowfunc snprintf
allowfunc socket
allowfunc sscanf
-allowfunc strdup
allowfunc vsnprintf
# define snprintf _snprintf
#endif
-#ifdef _WIN32
-# define strdup _strdup
-#endif
-
#ifdef _WIN32
# define CURL_STRNICMP(p1, p2, n) _strnicmp(p1, p2, n)
#elif defined(HAVE_STRCASECMP)
(long)our_getpid());
logmsg("Are-we-friendly question received");
- test->buffer = strdup(weare);
+ test->buffer = curlx_strdup(weare);
test->rptr = test->buffer; /* set read pointer */
test->bufsize = count; /* set total count */
test->rcount = count; /* set data left to read */