#include "tool_cb_wrt.h"
#include "tool_operate.h"
#include "tool_libinfo.h"
+#include "tool_strdup.h"
#include "memdebug.h" /* keep this as LAST include */
char *q;
char stop = '\0';
- /* simple implementation of strndup() */
- copy = malloc(len + 1);
+ copy = memdup0(ptr, len);
if(!copy)
return NULL;
- memcpy(copy, ptr, len);
- copy[len] = '\0';
p = copy;
if(*p == '\'' || *p == '"') {
goto locout;
/* Create a null-terminated and whitespace-stripped copy of Location: */
- copyloc = malloc(llen + 1);
+ copyloc = memdup0(loc, llen);
if(!copyloc)
goto locout;
- memcpy(copyloc, loc, llen);
- copyloc[llen] = 0;
/* The original URL to use as a base for a relative redirect URL */
if(curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &locurl))
*
***************************************************************************/
#include "tool_strdup.h"
+#include "memdebug.h" /* keep this as LAST include */
#ifndef HAVE_STRDUP
char *strdup(const char *str)
return newstr;
}
#endif
+
+char *memdup0(const char *data, size_t len)
+{
+ char *p = malloc(len + 1);
+ if(!p)
+ return NULL;
+ if(len)
+ memcpy(p, data, len);
+ p[len] = 0;
+ return p;
+}
#ifndef HAVE_STRDUP
extern char *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"
#include "memdebug.h" /* keep this as LAST include */
#define GLOBERROR(string, column, code) \
if(!pat->content.Set.elements)
return GLOBERROR("out of memory", 0, CURLE_OUT_OF_MEMORY);
- pat->content.Set.elements[0] = malloc(len + 1);
+ pat->content.Set.elements[0] = memdup0(fixed, len);
if(!pat->content.Set.elements[0])
return GLOBERROR("out of memory", 0, CURLE_OUT_OF_MEMORY);
- memcpy(pat->content.Set.elements[0], fixed, len);
- pat->content.Set.elements[0][len] = 0;
-
return CURLE_OK;
}
#include "tool_parsecfg.h"
#include "tool_paramhlp.h"
#include "tool_writeout_json.h"
+#include "tool_strdup.h"
#include "var.h"
#include "memdebug.h" /* keep this as LAST include */
#define MAX_EXPAND_CONTENT 10000000
#define MAX_VAR_LEN 128 /* max length of a name */
-static char *Memdup(const char *data, size_t len)
-{
- char *p = malloc(len + 1);
- if(!p)
- return NULL;
- if(len)
- memcpy(p, data, len);
- p[len] = 0;
- return p;
-}
-
/* free everything */
void varcleanup(struct GlobalConfig *global)
{
free(c);
clen = curlx_dyn_len(out);
- c = Memdup(curlx_dyn_ptr(out), clen);
+ c = memdup0(curlx_dyn_ptr(out), clen);
if(!c) {
err = PARAM_NO_MEM;
break;
if(p) {
memcpy(p->name, name, nlen);
- p->content = contalloc ? content : Memdup(content, clen);
+ p->content = contalloc ? content : memdup0(content, clen);
if(p->content) {
p->clen = clen;