util: add linear_memdup

convenience method; linear version of ralloc_memdup.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39494>
This commit is contained in:
Alyssa Rosenzweig 2026-01-23 14:14:44 -05:00 committed by Marge Bot
parent 870e233ca5
commit 598fcf2bf9
2 changed files with 13 additions and 0 deletions

View file

@ -1195,6 +1195,18 @@ ralloc_parent_of_linear_context(linear_ctx *ctx)
* calls are different.
*/
void *
linear_memdup(linear_ctx *ctx, const void *mem, size_t n)
{
void *ptr = linear_alloc_child(ctx, n);
if (unlikely(ptr == NULL))
return NULL;
memcpy(ptr, mem, n);
return ptr;
}
char *
linear_strdup(linear_ctx *ctx, const char *str)
{

View file

@ -672,6 +672,7 @@ void *linear_zalloc_child_array(linear_ctx *ctx, size_t size, unsigned count) MA
char *linear_strdup(linear_ctx *ctx, const char *str) MALLOCLIKE;
char *linear_asprintf(linear_ctx *ctx, const char *fmt, ...) PRINTFLIKE(2, 3) MALLOCLIKE;
char *linear_vasprintf(linear_ctx *ctx, const char *fmt, va_list args) MALLOCLIKE;
void *linear_memdup(linear_ctx *ctx, const void *mem, size_t n) MALLOCLIKE;
bool linear_asprintf_append(linear_ctx *ctx, char **str, const char *fmt, ...) PRINTFLIKE(3, 4);
bool linear_vasprintf_append(linear_ctx *ctx, char **str, const char *fmt,
va_list args);