windows: Provide a strndup(3) replacement

This commit is contained in:
Martin Willi
2014-06-04 15:53:02 +02:00
parent 8f3a3656d3
commit f3c809e615
2 changed files with 20 additions and 0 deletions
+15
View File
@@ -49,6 +49,21 @@ int usleep(useconds_t usec)
return 0;
}
/**
* See header.
*/
char* strndup(const char *s, size_t n)
{
char *dst;
n = min(strnlen(s, n), n);
dst = malloc(n + 1);
memcpy(dst, s, n);
dst[n] = '\0';
return dst;
}
/*
* See header.
*/
+5
View File
@@ -105,6 +105,11 @@ static inline char* strdup_windows(const char *src)
return dst;
}
/**
* strndup(3)
*/
char* strndup(const char *s, size_t n);
/**
* Provided via ws2_32
*/