vkd3d-common: Add vkd3d_strdup_n
There is no strndup on Windows. Signed-off-by: Joshua Ashton <joshua@froggi.es>
This commit is contained in:
parent
26f5745ea1
commit
a76daad03f
|
@ -32,6 +32,7 @@ bool vkd3d_export_strequal(const WCHAR *a, const WCHAR *b);
|
||||||
bool vkd3d_export_strequal_substr(const WCHAR *a, size_t n, const WCHAR *b);
|
bool vkd3d_export_strequal_substr(const WCHAR *a, size_t n, const WCHAR *b);
|
||||||
|
|
||||||
char *vkd3d_strdup(const char *str);
|
char *vkd3d_strdup(const char *str);
|
||||||
|
char *vkd3d_strdup_n(const char *str, size_t n);
|
||||||
WCHAR *vkd3d_wstrdup(const WCHAR *str);
|
WCHAR *vkd3d_wstrdup(const WCHAR *str);
|
||||||
WCHAR *vkd3d_wstrdup_n(const WCHAR *str, size_t n);
|
WCHAR *vkd3d_wstrdup_n(const WCHAR *str, size_t n);
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,23 @@ char *vkd3d_strdup(const char *str)
|
||||||
return duped;
|
return duped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *vkd3d_strdup_n(const char *str, size_t n)
|
||||||
|
{
|
||||||
|
char *duped;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
len = strnlen(str, n);
|
||||||
|
|
||||||
|
duped = vkd3d_malloc(len + 1);
|
||||||
|
if (duped)
|
||||||
|
{
|
||||||
|
memcpy(duped, str, len);
|
||||||
|
duped[len] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return duped;
|
||||||
|
}
|
||||||
|
|
||||||
WCHAR *vkd3d_wstrdup(const WCHAR *str)
|
WCHAR *vkd3d_wstrdup(const WCHAR *str)
|
||||||
{
|
{
|
||||||
WCHAR *duped;
|
WCHAR *duped;
|
||||||
|
|
Loading…
Reference in New Issue