diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-02-12 02:22:31 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-02-12 02:26:24 +0100 |
commit | 303680ebcd5adaac2934b63a0edc2d9d1a36d7fb (patch) | |
tree | bd2012dc6fa56f7259dbe2e5edd7ab3042f8e0a0 /lib/sqfs/xattr_reader.c | |
parent | ec7a522a520017327dd73b4d8e3787016ee1a31e (diff) |
Implement a more explicit object system
Make every dynamically allocated, opaque data structure inherit from
a common sqfs_object_t structure with common entry points (e.g. destroy).
This removes tons of public API functions and replaces them with a
simple sqfs_destroy instead. If semantics of the (until now implicit)
object system need to be extended, it can be much more conveniantely
done this way.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/xattr_reader.c')
-rw-r--r-- | lib/sqfs/xattr_reader.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/lib/sqfs/xattr_reader.c b/lib/sqfs/xattr_reader.c index d5b003b..97cf821 100644 --- a/lib/sqfs/xattr_reader.c +++ b/lib/sqfs/xattr_reader.c @@ -21,6 +21,8 @@ #include <errno.h> struct sqfs_xattr_reader_t { + sqfs_object_t base; + sqfs_u64 xattr_start; size_t num_id_blocks; @@ -34,6 +36,20 @@ struct sqfs_xattr_reader_t { sqfs_file_t *file; }; +static void xattr_reader_destroy(sqfs_object_t *obj) +{ + sqfs_xattr_reader_t *xr = (sqfs_xattr_reader_t *)obj; + + if (xr->kvrd != NULL) + sqfs_destroy(xr->kvrd); + + if (xr->idrd != NULL) + sqfs_destroy(xr->idrd); + + free(xr->id_block_starts); + free(xr); +} + int sqfs_xattr_reader_load_locations(sqfs_xattr_reader_t *xr) { sqfs_xattr_id_table_t idtbl; @@ -242,18 +258,6 @@ int sqfs_xattr_reader_get_desc(sqfs_xattr_reader_t *xr, sqfs_u32 idx, return 0; } -void sqfs_xattr_reader_destroy(sqfs_xattr_reader_t *xr) -{ - if (xr->kvrd != NULL) - sqfs_meta_reader_destroy(xr->kvrd); - - if (xr->idrd != NULL) - sqfs_meta_reader_destroy(xr->idrd); - - free(xr->id_block_starts); - free(xr); -} - sqfs_xattr_reader_t *sqfs_xattr_reader_create(sqfs_file_t *file, sqfs_super_t *super, sqfs_compressor_t *cmp) @@ -263,6 +267,7 @@ sqfs_xattr_reader_t *sqfs_xattr_reader_create(sqfs_file_t *file, if (xr == NULL) return NULL; + ((sqfs_object_t *)xr)->destroy = xattr_reader_destroy; xr->file = file; xr->super = super; @@ -286,6 +291,6 @@ sqfs_xattr_reader_t *sqfs_xattr_reader_create(sqfs_file_t *file, return xr; fail: - sqfs_xattr_reader_destroy(xr); + sqfs_destroy(xr); return NULL; } |