[Mesa-dev] [PATCH 1/3] vulkan/alloc: Add a vk_strdup helper

Grazvydas Ignotas notasas at gmail.com
Thu Aug 23 15:34:58 UTC 2018


On Thu, Aug 23, 2018 at 6:13 PM, Jason Ekstrand <jason at jlekstrand.net> wrote:
> ---
>  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);

Don't you need the nul char?

GraÅžvydas


More information about the mesa-dev mailing list