diff --git a/include/util/mem.h b/include/util/mem.h new file mode 100644 index 000000000..8971d2087 --- /dev/null +++ b/include/util/mem.h @@ -0,0 +1,14 @@ +#ifndef UTIL_MEM_H +#define UTIL_MEM_H + +#include +#include + +/** + * Allocate a new block of memory and copy *src to it, then store the address + * of the new allocation in *out. Returns true if it worked, or false if + * allocation failed. + */ +bool memdup(void *out, const void *src, size_t size); + +#endif // UTIL_MEM_H diff --git a/types/wlr_color_management_v1.c b/types/wlr_color_management_v1.c index b5e9a65fa..d9a3aba1b 100644 --- a/types/wlr_color_management_v1.c +++ b/types/wlr_color_management_v1.c @@ -1,12 +1,14 @@ #include #include #include + #include #include #include #include #include "render/color.h" +#include "util/mem.h" #define COLOR_MANAGEMENT_V1_VERSION 1 @@ -898,17 +900,6 @@ static void manager_handle_display_destroy(struct wl_listener *listener, void *d free(manager); } -static bool memdup(void *out, const void *src, size_t size) { - void *dst = malloc(size); - if (dst == NULL) { - return false; - } - memcpy(dst, src, size); - void **dst_ptr = out; - *dst_ptr = dst; - return true; -} - struct wlr_color_manager_v1 *wlr_color_manager_v1_create(struct wl_display *display, uint32_t version, const struct wlr_color_manager_v1_options *options) { assert(version <= COLOR_MANAGEMENT_V1_VERSION); diff --git a/util/mem.c b/util/mem.c new file mode 100644 index 000000000..cfd2f80e4 --- /dev/null +++ b/util/mem.c @@ -0,0 +1,16 @@ +#include +#include +#include + +#include "util/mem.h" + +bool memdup(void *out, const void *src, size_t size) { + void *dst = malloc(size); + if (dst == NULL) { + return false; + } + memcpy(dst, src, size); + void **dst_ptr = out; + *dst_ptr = dst; + return true; +} diff --git a/util/meson.build b/util/meson.build index fbdd54bbb..d67911e52 100644 --- a/util/meson.build +++ b/util/meson.build @@ -6,6 +6,7 @@ wlr_files += files( 'global.c', 'log.c', 'matrix.c', + 'mem.c', 'rect_union.c', 'region.c', 'set.c',