vulkan/alloc: Add a vk_strdup helper

Cc: "18.2" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
(cherry picked from commit 4ffb575da5)
This commit is contained in:
Jason Ekstrand 2018-01-29 18:11:38 -08:00 committed by Andres Gomez
parent 3d52cfe80b
commit 70e7336e66

View file

@ -67,6 +67,23 @@ vk_free(const VkAllocationCallbacks *alloc, void *data)
alloc->pfnFree(alloc->pUserData, data);
}
static inline char *
vk_strdup(const VkAllocationCallbacks *alloc, const char *s,
VkSystemAllocationScope scope)
{
if (s == NULL)
return NULL;
size_t size = strlen(s) + 1;
char *copy = vk_alloc(alloc, size, 1, scope);
if (copy == NULL)
return NULL;
memcpy(copy, s, size);
return copy;
}
static inline void *
vk_alloc2(const VkAllocationCallbacks *parent_alloc,
const VkAllocationCallbacks *alloc,