[common] all: implement strdup directly
Dr.Memory on Windows complains bitterly about invalid heap free as it doesn't seem to be able to track this function's allocations. As it's such a trivial function we can just implement it locally.
This commit is contained in:
1 parent
12d051d8c0
commit
3ed71a09f4
2 files changed
+24
No files matched your search
@@ -23,6 +23,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "common/stringutils.h"
|
||||
|
||||
@@ -89,3 +90,23 @@ bool str_containsValue(const char * list, char delimiter, const char * value)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
char * strdup(const char *s)
|
||||
{
|
||||
if (!s)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const ssize_t len = strlen(s) + 1;
|
||||
char * out = malloc(len);
|
||||
if (!out)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(out, s, len);
|
||||
return out;
|
||||
}
|
||||
Reference in new issue
Block a user