diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-03-03 19:43:54 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-03-04 00:58:53 +0100 |
commit | 44c81eeffe9c8820b1009a7a5c728782aa5ebf40 (patch) | |
tree | 544eceb6dc5633018e5147c88ca9b07dd0fb54d9 /lib/sqfs/id_table.c | |
parent | 6f47796dc0761fac359ec59ce26c7af5154e538d (diff) |
Add a generic copying mechanism to sqfs_object_t
This patch adds a deep-copy callback to sqfs_object_t and removes the
copying mechanism from sqfs_compressor_t. This is also interesting for
other types.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/id_table.c')
-rw-r--r-- | lib/sqfs/id_table.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/sqfs/id_table.c b/lib/sqfs/id_table.c index 86f2809..e3d386e 100644 --- a/lib/sqfs/id_table.c +++ b/lib/sqfs/id_table.c @@ -32,6 +32,30 @@ static void id_table_destroy(sqfs_object_t *obj) free(tbl); } +static sqfs_object_t *id_table_copy(const sqfs_object_t *obj) +{ + const sqfs_id_table_t *tbl = (const sqfs_id_table_t *)obj; + sqfs_id_table_t *copy; + + copy = malloc(sizeof(*copy)); + if (copy == NULL) + return NULL; + + memcpy(copy, tbl, sizeof(*tbl)); + + copy->num_ids = tbl->num_ids; + copy->max_ids = tbl->num_ids; + copy->ids = malloc(tbl->num_ids * sizeof(tbl->ids[0])); + + if (copy->ids == NULL) { + free(copy); + return NULL; + } + + memcpy(copy->ids, tbl->ids, tbl->num_ids * sizeof(tbl->ids[0])); + return (sqfs_object_t *)copy; +} + sqfs_id_table_t *sqfs_id_table_create(sqfs_u32 flags) { sqfs_id_table_t *tbl; @@ -43,6 +67,7 @@ sqfs_id_table_t *sqfs_id_table_create(sqfs_u32 flags) if (tbl != NULL) { ((sqfs_object_t *)tbl)->destroy = id_table_destroy; + ((sqfs_object_t *)tbl)->copy = id_table_copy; } return tbl; |