mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-10-29 05:40:12 -04:00
util/mem: Move memdup to new util/mem.c file
This seems handy and I want to use this in wlr_color_representation.
This commit is contained in:
parent
c14aa1d0b8
commit
f5dc6416f0
4 changed files with 33 additions and 11 deletions
14
include/util/mem.h
Normal file
14
include/util/mem.h
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef UTIL_MEM_H
|
||||||
|
#define UTIL_MEM_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <wlr/types/wlr_color_management_v1.h>
|
#include <wlr/types/wlr_color_management_v1.h>
|
||||||
#include <wlr/types/wlr_compositor.h>
|
#include <wlr/types/wlr_compositor.h>
|
||||||
#include <wlr/types/wlr_output.h>
|
#include <wlr/types/wlr_output.h>
|
||||||
#include <wlr/util/addon.h>
|
#include <wlr/util/addon.h>
|
||||||
|
|
||||||
#include "render/color.h"
|
#include "render/color.h"
|
||||||
|
#include "util/mem.h"
|
||||||
|
|
||||||
#define COLOR_MANAGEMENT_V1_VERSION 1
|
#define COLOR_MANAGEMENT_V1_VERSION 1
|
||||||
|
|
||||||
|
|
@ -898,17 +900,6 @@ static void manager_handle_display_destroy(struct wl_listener *listener, void *d
|
||||||
free(manager);
|
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,
|
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) {
|
uint32_t version, const struct wlr_color_manager_v1_options *options) {
|
||||||
assert(version <= COLOR_MANAGEMENT_V1_VERSION);
|
assert(version <= COLOR_MANAGEMENT_V1_VERSION);
|
||||||
|
|
|
||||||
16
util/mem.c
Normal file
16
util/mem.c
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,7 @@ wlr_files += files(
|
||||||
'global.c',
|
'global.c',
|
||||||
'log.c',
|
'log.c',
|
||||||
'matrix.c',
|
'matrix.c',
|
||||||
|
'mem.c',
|
||||||
'rect_union.c',
|
'rect_union.c',
|
||||||
'region.c',
|
'region.c',
|
||||||
'set.c',
|
'set.c',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue