summaryrefslogtreecommitdiff
path: root/lib/sqfs/meta_writer.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-12 02:22:31 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-12 02:26:24 +0100
commit303680ebcd5adaac2934b63a0edc2d9d1a36d7fb (patch)
treebd2012dc6fa56f7259dbe2e5edd7ab3042f8e0a0 /lib/sqfs/meta_writer.c
parentec7a522a520017327dd73b4d8e3787016ee1a31e (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/meta_writer.c')
-rw-r--r--lib/sqfs/meta_writer.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/lib/sqfs/meta_writer.c b/lib/sqfs/meta_writer.c
index acb2235..46a67cd 100644
--- a/lib/sqfs/meta_writer.c
+++ b/lib/sqfs/meta_writer.c
@@ -25,6 +25,8 @@ typedef struct meta_block_t {
} meta_block_t;
struct sqfs_meta_writer_t {
+ sqfs_object_t base;
+
/* A byte offset into the uncompressed data of the current block */
size_t offset;
@@ -53,6 +55,20 @@ static int write_block(sqfs_file_t *file, meta_block_t *outblk)
return file->write_at(file, off, outblk->data, count + 2);
}
+static void meta_writer_destroy(sqfs_object_t *obj)
+{
+ sqfs_meta_writer_t *m = (sqfs_meta_writer_t *)obj;
+ meta_block_t *blk;
+
+ while (m->list != NULL) {
+ blk = m->list;
+ m->list = blk->next;
+ free(blk);
+ }
+
+ free(m);
+}
+
sqfs_meta_writer_t *sqfs_meta_writer_create(sqfs_file_t *file,
sqfs_compressor_t *cmp,
sqfs_u32 flags)
@@ -66,25 +82,13 @@ sqfs_meta_writer_t *sqfs_meta_writer_create(sqfs_file_t *file,
if (m == NULL)
return NULL;
+ ((sqfs_object_t *)m)->destroy = meta_writer_destroy;
m->cmp = cmp;
m->file = file;
m->flags = flags;
return m;
}
-void sqfs_meta_writer_destroy(sqfs_meta_writer_t *m)
-{
- meta_block_t *blk;
-
- while (m->list != NULL) {
- blk = m->list;
- m->list = blk->next;
- free(blk);
- }
-
- free(m);
-}
-
int sqfs_meta_writer_flush(sqfs_meta_writer_t *m)
{
meta_block_t *outblk;