windows: Provide a strdup variant safe when passing zero-length strings

This commit is contained in:
Martin Willi 2013-10-17 16:23:43 +02:00
parent d8e56dfe32
commit a506b922f3
1 changed files with 15 additions and 0 deletions

View File

@ -67,6 +67,21 @@ static inline void srandom(unsigned int seed)
srand(seed);
}
/**
* strdup(3), the Windows variant can't free(strdup("")) and others
*/
#define strdup strdup_windows
static inline char* strdup_windows(const char *src)
{
size_t len;
char *dst;
len = strlen(src) + 1;
dst = malloc(len);
memcpy(dst, src, len);
return dst;
}
/**
* Provided via ws2_32
*/