58 lines
1.5 KiB
Diff
58 lines
1.5 KiB
Diff
|
From 28f1c140374d1ecda65e3d59cca72352c3a07774 Mon Sep 17 00:00:00 2001
|
||
|
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
|
||
|
Date: Thu, 6 Jan 2022 11:45:12 -0800
|
||
|
Subject: [PATCH] shared/util: Add util_memdup
|
||
|
|
||
|
This adds util_memdup which is intended to replace g_memdup since
|
||
|
replacing that with g_memdup2 requires bumping the glib version.
|
||
|
|
||
|
(cherry picked from commit 9f09e69ecb077082301dafb745856e1f3731aaa7)
|
||
|
Signed-off-by: Thomas Devoogdt <thomas.devoogdt@gmail.com>
|
||
|
---
|
||
|
src/shared/util.c | 16 ++++++++++++++++
|
||
|
src/shared/util.h | 1 +
|
||
|
2 files changed, 17 insertions(+)
|
||
|
|
||
|
diff --git a/src/shared/util.c b/src/shared/util.c
|
||
|
index 93110047b..6e1c83057 100644
|
||
|
--- a/src/shared/util.c
|
||
|
+++ b/src/shared/util.c
|
||
|
@@ -41,6 +41,22 @@ void *util_malloc(size_t size)
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
+void *util_memdup(const void *src, size_t size)
|
||
|
+{
|
||
|
+ void *cpy;
|
||
|
+
|
||
|
+ if (!src || !size)
|
||
|
+ return NULL;
|
||
|
+
|
||
|
+ cpy = util_malloc(size);
|
||
|
+ if (!cpy)
|
||
|
+ return NULL;
|
||
|
+
|
||
|
+ memcpy(cpy, src, size);
|
||
|
+
|
||
|
+ return cpy;
|
||
|
+}
|
||
|
+
|
||
|
void util_debug_va(util_debug_func_t function, void *user_data,
|
||
|
const char *format, va_list va)
|
||
|
{
|
||
|
diff --git a/src/shared/util.h b/src/shared/util.h
|
||
|
index 11d09979d..8ef6132c4 100644
|
||
|
--- a/src/shared/util.h
|
||
|
+++ b/src/shared/util.h
|
||
|
@@ -87,6 +87,7 @@ char *strdelimit(char *str, char *del, char c);
|
||
|
int strsuffix(const char *str, const char *suffix);
|
||
|
|
||
|
void *util_malloc(size_t size);
|
||
|
+void *util_memdup(const void *src, size_t size);
|
||
|
|
||
|
typedef void (*util_debug_func_t)(const char *str, void *user_data);
|
||
|
|
||
|
--
|
||
|
2.17.1
|
||
|
|