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/dir_reader.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/dir_reader.c')
-rw-r--r-- | lib/sqfs/dir_reader.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/sqfs/dir_reader.c b/lib/sqfs/dir_reader.c index 4e2a5b8..8e23ddb 100644 --- a/lib/sqfs/dir_reader.c +++ b/lib/sqfs/dir_reader.c @@ -45,6 +45,32 @@ static void dir_reader_destroy(sqfs_object_t *obj) free(rd); } +static sqfs_object_t *dir_reader_copy(const sqfs_object_t *obj) +{ + const sqfs_dir_reader_t *rd = (const sqfs_dir_reader_t *)obj; + sqfs_dir_reader_t *copy = malloc(sizeof(*copy)); + + if (copy == NULL) + return NULL; + + memcpy(copy, rd, sizeof(*copy)); + + copy->meta_inode = sqfs_copy(rd->meta_inode); + if (copy->meta_inode == NULL) + goto fail_mino; + + copy->meta_dir = sqfs_copy(rd->meta_dir); + if (copy->meta_dir == NULL) + goto fail_mdir; + + return (sqfs_object_t *)copy; +fail_mdir: + sqfs_destroy(copy->meta_inode); +fail_mino: + free(copy); + return NULL; +} + sqfs_dir_reader_t *sqfs_dir_reader_create(const sqfs_super_t *super, sqfs_compressor_t *cmp, sqfs_file_t *file) @@ -83,6 +109,7 @@ sqfs_dir_reader_t *sqfs_dir_reader_create(const sqfs_super_t *super, } ((sqfs_object_t *)rd)->destroy = dir_reader_destroy; + ((sqfs_object_t *)rd)->copy = dir_reader_copy; rd->super = super; return rd; } |