From 4ffb575da59fd3aece02734ca4fd3212d5002d55 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Mon, 29 Jan 2018 18:11:38 -0800 Subject: vulkan/alloc: Add a vk_strdup helper Cc: "18.2" Reviewed-by: Lionel Landwerlin --- src/vulkan/util/vk_alloc.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/vulkan/util/vk_alloc.h b/src/vulkan/util/vk_alloc.h index f58a80625a8..2e807a96d9e 100644 --- a/src/vulkan/util/vk_alloc.h +++ b/src/vulkan/util/vk_alloc.h @@ -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, -- cgit v1.2.3