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_writer.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_writer.c')
-rw-r--r-- | lib/sqfs/xattr_writer.c | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/lib/sqfs/xattr_writer.c b/lib/sqfs/xattr_writer.c index 047e411..827d0c5 100644 --- a/lib/sqfs/xattr_writer.c +++ b/lib/sqfs/xattr_writer.c @@ -99,6 +99,8 @@ typedef struct kv_block_desc_t { } kv_block_desc_t; struct sqfs_xattr_writer_t { + sqfs_object_t base; + str_table_t keys; str_table_t values; @@ -113,6 +115,23 @@ struct sqfs_xattr_writer_t { }; +static void xattr_writer_destroy(sqfs_object_t *obj) +{ + sqfs_xattr_writer_t *xwr = (sqfs_xattr_writer_t *)obj; + kv_block_desc_t *blk; + + while (xwr->kv_blocks != NULL) { + blk = xwr->kv_blocks; + xwr->kv_blocks = xwr->kv_blocks->next; + free(blk); + } + + free(xwr->kv_pairs); + str_table_cleanup(&xwr->values); + str_table_cleanup(&xwr->keys); + free(xwr); +} + sqfs_xattr_writer_t *sqfs_xattr_writer_create(void) { sqfs_xattr_writer_t *xwr = calloc(1, sizeof(*xwr)); @@ -129,6 +148,7 @@ sqfs_xattr_writer_t *sqfs_xattr_writer_create(void) if (xwr->kv_pairs == NULL) goto fail_pairs; + ((sqfs_object_t *)xwr)->destroy = xattr_writer_destroy; return xwr; fail_pairs: str_table_cleanup(&xwr->values); @@ -139,22 +159,6 @@ fail_keys: return NULL; } -void sqfs_xattr_writer_destroy(sqfs_xattr_writer_t *xwr) -{ - kv_block_desc_t *blk; - - while (xwr->kv_blocks != NULL) { - blk = xwr->kv_blocks; - xwr->kv_blocks = xwr->kv_blocks->next; - free(blk); - } - - free(xwr->kv_pairs); - str_table_cleanup(&xwr->values); - str_table_cleanup(&xwr->keys); - free(xwr); -} - int sqfs_xattr_writer_begin(sqfs_xattr_writer_t *xwr) { xwr->kv_start = xwr->num_pairs; @@ -603,6 +607,6 @@ int sqfs_xattr_writer_flush(sqfs_xattr_writer_t *xwr, sqfs_file_t *file, locations, count); out: free(locations); - sqfs_meta_writer_destroy(mw); + sqfs_destroy(mw); return err; } |