From 4160b50a0b4c51f8b7191928cdf38d9fb0147fe2 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 4 Dec 2022 00:39:47 +0100 Subject: Add a helper function to initialize libsquashfs objects Signed-off-by: David Oberhollenzer --- include/sqfs/predef.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'include') diff --git a/include/sqfs/predef.h b/include/sqfs/predef.h index f4b544b..39da692 100644 --- a/include/sqfs/predef.h +++ b/include/sqfs/predef.h @@ -162,6 +162,22 @@ static SQFS_INLINE void *sqfs_copy(const void *obj) return NULL; } +/** + * @brief Initialize an object with default callbacks. + * + * @memberof sqfs_object_t + * + * @param obj A pointer to an uninitialized object + */ +static SQFS_INLINE +void sqfs_object_init(void *obj, + void (*destroy_fn)(sqfs_object_t *), + sqfs_object_t *(*copy_fn)(const sqfs_object_t *)) +{ + ((sqfs_object_t *)obj)->destroy = destroy_fn; + ((sqfs_object_t *)obj)->copy = copy_fn; +} + #ifdef __cplusplus extern "C" { #endif -- cgit v1.2.3