Mesa (staging/18.2): vulkan/alloc: Add a vk_strdup helper

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Aug 30 12:59:02 UTC 2018


Module: Mesa
Branch: staging/18.2
Commit: 70e7336e66a37cb700dbece1b146ba3f79e2ed85
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=70e7336e66a37cb700dbece1b146ba3f79e2ed85

Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date:   Mon Jan 29 18:11:38 2018 -0800

vulkan/alloc: Add a vk_strdup helper

Cc: "18.2" <mesa-stable at lists.freedesktop.org>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
(cherry picked from commit 4ffb575da59fd3aece02734ca4fd3212d5002d55)

---

 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 f58a80625a..2e807a96d9 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,




More information about the mesa-commit mailing list