[Mesa-dev] [PATCH 1/3] vulkan/alloc: Add a vk_strdup helper
Jason Ekstrand
jason at jlekstrand.net
Thu Aug 23 15:13:41 UTC 2018
---
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..bc2bb7509e4 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 len = strlen(s);
+ char *copy = vk_alloc(alloc, len, 1, scope);
+ if (copy == NULL)
+ return NULL;
+
+ memcpy(copy, s, len);
+
+ return copy;
+}
+
static inline void *
vk_alloc2(const VkAllocationCallbacks *parent_alloc,
const VkAllocationCallbacks *alloc,
--
2.17.1
More information about the mesa-dev
mailing list