diff options
-rw-r--r-- | include/sqfs/predef.h | 16 | ||||
-rw-r--r-- | lib/common/comp_lzo.c | 4 | ||||
-rw-r--r-- | lib/common/data_writer_ostream.c | 4 | ||||
-rw-r--r-- | lib/io/compress/ostream_compressor.c | 6 | ||||
-rw-r--r-- | lib/io/uncompress/istream_compressor.c | 6 | ||||
-rw-r--r-- | lib/io/unix/istream.c | 8 | ||||
-rw-r--r-- | lib/io/unix/ostream.c | 6 | ||||
-rw-r--r-- | lib/io/win32/istream.c | 8 | ||||
-rw-r--r-- | lib/io/win32/ostream.c | 6 | ||||
-rw-r--r-- | lib/sqfs/block_processor/block_processor.c | 3 | ||||
-rw-r--r-- | lib/sqfs/block_writer.c | 3 | ||||
-rw-r--r-- | lib/sqfs/comp/gzip.c | 4 | ||||
-rw-r--r-- | lib/sqfs/comp/lz4.c | 4 | ||||
-rw-r--r-- | lib/sqfs/comp/lzma.c | 4 | ||||
-rw-r--r-- | lib/sqfs/comp/xz.c | 4 | ||||
-rw-r--r-- | lib/sqfs/comp/zstd.c | 4 | ||||
-rw-r--r-- | lib/sqfs/data_reader.c | 4 | ||||
-rw-r--r-- | lib/sqfs/dir_reader/dir_reader.c | 4 | ||||
-rw-r--r-- | lib/sqfs/dir_writer.c | 3 | ||||
-rw-r--r-- | lib/sqfs/frag_table.c | 4 | ||||
-rw-r--r-- | lib/sqfs/id_table.c | 4 | ||||
-rw-r--r-- | lib/sqfs/meta_reader.c | 4 | ||||
-rw-r--r-- | lib/sqfs/meta_writer.c | 3 | ||||
-rw-r--r-- | lib/sqfs/unix/io_file.c | 4 | ||||
-rw-r--r-- | lib/sqfs/win32/io_file.c | 4 | ||||
-rw-r--r-- | lib/sqfs/xattr/xattr_reader.c | 3 | ||||
-rw-r--r-- | lib/sqfs/xattr/xattr_writer.c | 5 |
27 files changed, 72 insertions, 60 deletions
diff --git a/include/sqfs/predef.h b/include/sqfs/predef.h index f4b544b..39da692 100644 --- a/include/sqfs/predef.h +++ b/include/sqfs/predef.h @@ -162,6 +162,22 @@ static SQFS_INLINE void *sqfs_copy(const void *obj) return NULL; } +/** + * @brief Initialize an object with default callbacks. + * + * @memberof sqfs_object_t + * + * @param obj A pointer to an uninitialized object + */ +static SQFS_INLINE +void sqfs_object_init(void *obj, + void (*destroy_fn)(sqfs_object_t *), + sqfs_object_t *(*copy_fn)(const sqfs_object_t *)) +{ + ((sqfs_object_t *)obj)->destroy = destroy_fn; + ((sqfs_object_t *)obj)->copy = copy_fn; +} + #ifdef __cplusplus extern "C" { #endif diff --git a/lib/common/comp_lzo.c b/lib/common/comp_lzo.c index 92a081c..2021d34 100644 --- a/lib/common/comp_lzo.c +++ b/lib/common/comp_lzo.c @@ -266,6 +266,8 @@ int lzo_compressor_create(const sqfs_compressor_config_t *cfg, if (lzo == NULL) return SQFS_ERROR_ALLOC; + sqfs_object_init(lzo, lzo_destroy, lzo_create_copy); + lzo->block_size = cfg->block_size; lzo->algorithm = cfg->opt.lzo.algorithm; lzo->level = cfg->level; @@ -277,8 +279,6 @@ int lzo_compressor_create(const sqfs_compressor_config_t *cfg, lzo_uncomp_block : lzo_comp_block; base->write_options = lzo_write_options; base->read_options = lzo_read_options; - ((sqfs_object_t *)base)->copy = lzo_create_copy; - ((sqfs_object_t *)base)->destroy = lzo_destroy; *out = base; return 0; diff --git a/lib/common/data_writer_ostream.c b/lib/common/data_writer_ostream.c index 94a04f2..fbd0431 100644 --- a/lib/common/data_writer_ostream.c +++ b/lib/common/data_writer_ostream.c @@ -64,7 +64,6 @@ ostream_t *data_writer_ostream_create(const char *filename, int flags) { data_writer_ostream_t *strm = calloc(1, sizeof(*strm)); - sqfs_object_t *obj = (sqfs_object_t *)strm; ostream_t *base = (ostream_t *)strm; int ret; @@ -73,6 +72,8 @@ ostream_t *data_writer_ostream_create(const char *filename, return NULL; } + sqfs_object_init(strm, stream_destroy, NULL); + ret = sqfs_block_processor_begin_file(proc, inode, NULL, flags); if (ret != 0) { @@ -86,6 +87,5 @@ ostream_t *data_writer_ostream_create(const char *filename, base->append = stream_append; base->flush = stream_flush; base->get_filename = stream_get_filename; - obj->destroy = stream_destroy; return base; } diff --git a/lib/io/compress/ostream_compressor.c b/lib/io/compress/ostream_compressor.c index 314ce6b..f63a3d2 100644 --- a/lib/io/compress/ostream_compressor.c +++ b/lib/io/compress/ostream_compressor.c @@ -63,7 +63,6 @@ static void comp_destroy(sqfs_object_t *obj) ostream_t *ostream_compressor_create(ostream_t *strm, int comp_id) { ostream_comp_t *comp = NULL; - sqfs_object_t *obj; ostream_t *base; switch (comp_id) { @@ -94,6 +93,8 @@ ostream_t *ostream_compressor_create(ostream_t *strm, int comp_id) if (comp == NULL) return NULL; + sqfs_object_init(comp, comp_destroy, NULL); + comp->wrapped = strm; comp->inbuf_used = 0; @@ -101,8 +102,5 @@ ostream_t *ostream_compressor_create(ostream_t *strm, int comp_id) base->append = comp_append; base->flush = comp_flush; base->get_filename = comp_get_filename; - - obj = (sqfs_object_t *)comp; - obj->destroy = comp_destroy; return base; } diff --git a/lib/io/uncompress/istream_compressor.c b/lib/io/uncompress/istream_compressor.c index ab9ad8b..1c73e3a 100644 --- a/lib/io/uncompress/istream_compressor.c +++ b/lib/io/uncompress/istream_compressor.c @@ -25,7 +25,6 @@ static void comp_destroy(sqfs_object_t *obj) istream_t *istream_compressor_create(istream_t *strm, int comp_id) { istream_comp_t *comp = NULL; - sqfs_object_t *obj; istream_t *base; switch (comp_id) { @@ -56,14 +55,13 @@ istream_t *istream_compressor_create(istream_t *strm, int comp_id) if (comp == NULL) return NULL; + sqfs_object_init(comp, comp_destroy, NULL); + comp->wrapped = strm; base = (istream_t *)comp; base->get_filename = comp_get_filename; base->buffer = comp->uncompressed; base->eof = false; - - obj = (sqfs_object_t *)comp; - obj->destroy = comp_destroy; return base; } diff --git a/lib/io/unix/istream.c b/lib/io/unix/istream.c index e0b728c..f8cffad 100644 --- a/lib/io/unix/istream.c +++ b/lib/io/unix/istream.c @@ -65,7 +65,6 @@ static void file_destroy(sqfs_object_t *obj) istream_t *istream_open_file(const char *path) { file_istream_t *file = calloc(1, sizeof(*file)); - sqfs_object_t *obj = (sqfs_object_t *)file; istream_t *strm = (istream_t *)file; if (file == NULL) { @@ -73,6 +72,8 @@ istream_t *istream_open_file(const char *path) return NULL; } + sqfs_object_init(file, file_destroy, NULL); + file->path = strdup(path); if (file->path == NULL) { perror(path); @@ -88,7 +89,6 @@ istream_t *istream_open_file(const char *path) strm->buffer = file->buffer; strm->precache = file_precache; strm->get_filename = file_get_filename; - obj->destroy = file_destroy; return strm; fail_path: free(file->path); @@ -100,12 +100,13 @@ fail_free: istream_t *istream_open_stdin(void) { file_istream_t *file = calloc(1, sizeof(*file)); - sqfs_object_t *obj = (sqfs_object_t *)file; istream_t *strm = (istream_t *)file; if (file == NULL) goto fail; + sqfs_object_init(file, file_destroy, NULL); + file->path = strdup("stdin"); if (file->path == NULL) goto fail; @@ -114,7 +115,6 @@ istream_t *istream_open_stdin(void) strm->buffer = file->buffer; strm->precache = file_precache; strm->get_filename = file_get_filename; - obj->destroy = file_destroy; return strm; fail: perror("creating file wrapper for stdin"); diff --git a/lib/io/unix/ostream.c b/lib/io/unix/ostream.c index 17f1998..6ed18e6 100644 --- a/lib/io/unix/ostream.c +++ b/lib/io/unix/ostream.c @@ -107,7 +107,6 @@ static const char *file_get_filename(ostream_t *strm) ostream_t *ostream_open_file(const char *path, int flags) { file_ostream_t *file = calloc(1, sizeof(*file)); - sqfs_object_t *obj = (sqfs_object_t *)file; ostream_t *strm = (ostream_t *)file; if (file == NULL) { @@ -115,6 +114,8 @@ ostream_t *ostream_open_file(const char *path, int flags) return NULL; } + sqfs_object_init(file, file_destroy, NULL); + file->path = strdup(path); if (file->path == NULL) { perror(path); @@ -138,7 +139,6 @@ ostream_t *ostream_open_file(const char *path, int flags) strm->append = file_append; strm->flush = file_flush; strm->get_filename = file_get_filename; - obj->destroy = file_destroy; return strm; fail_path: free(file->path); @@ -150,7 +150,6 @@ fail_free: ostream_t *ostream_open_stdout(void) { file_ostream_t *file = calloc(1, sizeof(*file)); - sqfs_object_t *obj = (sqfs_object_t *)file; ostream_t *strm = (ostream_t *)file; if (file == NULL) @@ -164,7 +163,6 @@ ostream_t *ostream_open_stdout(void) strm->append = file_append; strm->flush = file_flush; strm->get_filename = file_get_filename; - obj->destroy = file_destroy; return strm; fail: perror("creating file wrapper for stdout"); diff --git a/lib/io/win32/istream.c b/lib/io/win32/istream.c index b591584..be3d829 100644 --- a/lib/io/win32/istream.c +++ b/lib/io/win32/istream.c @@ -77,7 +77,6 @@ static void file_destroy(sqfs_object_t *obj) istream_t *istream_open_file(const char *path) { file_istream_t *file = calloc(1, sizeof(*file)); - sqfs_object_t *obj = (sqfs_object_t *)file; istream_t *strm = (istream_t *)file; WCHAR *wpath = NULL; @@ -86,6 +85,8 @@ istream_t *istream_open_file(const char *path) return NULL; } + sqfs_object_init(file, file_destroy, NULL); + wpath = path_to_windows(path); if (wpath == NULL) goto fail_free; @@ -109,7 +110,6 @@ istream_t *istream_open_file(const char *path) strm->buffer = file->buffer; strm->precache = file_precache; strm->get_filename = file_get_filename; - obj->destroy = file_destroy; return strm; fail_path: free(file->path); @@ -122,7 +122,6 @@ fail_free: istream_t *istream_open_stdin(void) { file_istream_t *file = calloc(1, sizeof(*file)); - sqfs_object_t *obj = (sqfs_object_t *)file; istream_t *strm = (istream_t *)file; if (file == NULL) { @@ -130,9 +129,10 @@ istream_t *istream_open_stdin(void) return NULL; } + sqfs_object_init(file, file_destroy, NULL); + strm->buffer = file->buffer; strm->precache = file_precache; strm->get_filename = file_get_filename; - obj->destroy = file_destroy; return strm; } diff --git a/lib/io/win32/ostream.c b/lib/io/win32/ostream.c index 2bd78c8..0fe04f3 100644 --- a/lib/io/win32/ostream.c +++ b/lib/io/win32/ostream.c @@ -135,6 +135,8 @@ ostream_t *ostream_open_file(const char *path, int flags) return NULL; } + sqfs_object_init(file, file_destroy, NULL); + wpath = path_to_windows(path); if (wpath == NULL) goto fail_free; @@ -169,7 +171,6 @@ ostream_t *ostream_open_file(const char *path, int flags) strm->append = file_append; strm->flush = file_flush; strm->get_filename = file_get_filename; - obj->destroy = file_destroy; return strm; fail_path: free(file->path); @@ -189,9 +190,10 @@ ostream_t *ostream_open_stdout(void) return NULL; } + sqfs_object_init(strm, stdout_destroy, NULL); + strm->append = stdout_append; strm->flush = stdout_flush; strm->get_filename = stdout_get_filename; - obj->destroy = stdout_destroy; return strm; } diff --git a/lib/sqfs/block_processor/block_processor.c b/lib/sqfs/block_processor/block_processor.c index 97b8958..e223718 100644 --- a/lib/sqfs/block_processor/block_processor.c +++ b/lib/sqfs/block_processor/block_processor.c @@ -268,6 +268,8 @@ int sqfs_block_processor_create_ex(const sqfs_block_processor_desc_t *desc, if (proc == NULL) return SQFS_ERROR_ALLOC; + sqfs_object_init(proc, block_processor_destroy, NULL); + proc->max_backlog = desc->max_backlog; proc->max_block_size = desc->max_block_size; proc->frag_tbl = desc->tbl; @@ -275,7 +277,6 @@ int sqfs_block_processor_create_ex(const sqfs_block_processor_desc_t *desc, proc->file = desc->file; proc->uncmp = desc->uncmp; proc->stats.size = sizeof(proc->stats); - ((sqfs_object_t *)proc)->destroy = block_processor_destroy; /* we need at least one current data block + one fragment block */ if (proc->max_backlog < 3) diff --git a/lib/sqfs/block_writer.c b/lib/sqfs/block_writer.c index 7302736..1612986 100644 --- a/lib/sqfs/block_writer.c +++ b/lib/sqfs/block_writer.c @@ -219,9 +219,10 @@ sqfs_block_writer_t *sqfs_block_writer_create(sqfs_file_t *file, if (wr == NULL) return NULL; + sqfs_object_init(wr, block_writer_destroy, NULL); + ((sqfs_block_writer_t *)wr)->write_data_block = write_data_block; ((sqfs_block_writer_t *)wr)->get_block_count = get_block_count; - ((sqfs_object_t *)wr)->destroy = block_writer_destroy; wr->flags = flags; wr->file = file; wr->devblksz = devblksz; diff --git a/lib/sqfs/comp/gzip.c b/lib/sqfs/comp/gzip.c index 39d4227..beacfb8 100644 --- a/lib/sqfs/comp/gzip.c +++ b/lib/sqfs/comp/gzip.c @@ -277,6 +277,8 @@ int gzip_compressor_create(const sqfs_compressor_config_t *cfg, if (gzip == NULL) return SQFS_ERROR_ALLOC; + sqfs_object_init(gzip, gzip_destroy, gzip_create_copy); + gzip->opt.level = cfg->level; gzip->opt.window = cfg->opt.gzip.window_size; gzip->opt.strategies = cfg->flags & SQFS_COMP_FLAG_GZIP_ALL; @@ -286,8 +288,6 @@ int gzip_compressor_create(const sqfs_compressor_config_t *cfg, base->do_block = gzip_do_block; base->write_options = gzip_write_options; base->read_options = gzip_read_options; - ((sqfs_object_t *)base)->copy = gzip_create_copy; - ((sqfs_object_t *)base)->destroy = gzip_destroy; if (gzip->compress) { ret = deflateInit2(&gzip->strm, cfg->level, diff --git a/lib/sqfs/comp/lz4.c b/lib/sqfs/comp/lz4.c index 152ae75..77f4a6e 100644 --- a/lib/sqfs/comp/lz4.c +++ b/lib/sqfs/comp/lz4.c @@ -156,6 +156,8 @@ int lz4_compressor_create(const sqfs_compressor_config_t *cfg, if (lz4 == NULL) return SQFS_ERROR_ALLOC; + sqfs_object_init(lz4, lz4_destroy, lz4_create_copy); + lz4->high_compression = (cfg->flags & SQFS_COMP_FLAG_LZ4_HC) != 0; lz4->block_size = cfg->block_size; @@ -164,8 +166,6 @@ int lz4_compressor_create(const sqfs_compressor_config_t *cfg, lz4_uncomp_block : lz4_comp_block; base->write_options = lz4_write_options; base->read_options = lz4_read_options; - ((sqfs_object_t *)base)->copy = lz4_create_copy; - ((sqfs_object_t *)base)->destroy = lz4_destroy; *out = base; return 0; diff --git a/lib/sqfs/comp/lzma.c b/lib/sqfs/comp/lzma.c index 01e6042..5456603 100644 --- a/lib/sqfs/comp/lzma.c +++ b/lib/sqfs/comp/lzma.c @@ -260,6 +260,8 @@ int lzma_compressor_create(const sqfs_compressor_config_t *cfg, if (lzma == NULL) return SQFS_ERROR_ALLOC; + sqfs_object_init(lzma, lzma_destroy, lzma_create_copy); + lzma->block_size = cfg->block_size; lzma->flags = cfg->flags; lzma->level = cfg->level; @@ -273,8 +275,6 @@ int lzma_compressor_create(const sqfs_compressor_config_t *cfg, lzma_uncomp_block : lzma_comp_block; base->write_options = lzma_write_options; base->read_options = lzma_read_options; - ((sqfs_object_t *)base)->copy = lzma_create_copy; - ((sqfs_object_t *)base)->destroy = lzma_destroy; *out = base; return 0; diff --git a/lib/sqfs/comp/xz.c b/lib/sqfs/comp/xz.c index 3fb27b2..13545ed 100644 --- a/lib/sqfs/comp/xz.c +++ b/lib/sqfs/comp/xz.c @@ -304,6 +304,8 @@ int xz_compressor_create(const sqfs_compressor_config_t *cfg, if (xz == NULL) return SQFS_ERROR_ALLOC; + sqfs_object_init(xz, xz_destroy, xz_create_copy); + xz->flags = cfg->flags; xz->dict_size = cfg->opt.xz.dict_size; xz->block_size = cfg->block_size; @@ -316,8 +318,6 @@ int xz_compressor_create(const sqfs_compressor_config_t *cfg, xz_uncomp_block : xz_comp_block; base->write_options = xz_write_options; base->read_options = xz_read_options; - ((sqfs_object_t *)base)->copy = xz_create_copy; - ((sqfs_object_t *)base)->destroy = xz_destroy; *out = base; return 0; diff --git a/lib/sqfs/comp/zstd.c b/lib/sqfs/comp/zstd.c index af5bd84..a6d7975 100644 --- a/lib/sqfs/comp/zstd.c +++ b/lib/sqfs/comp/zstd.c @@ -151,6 +151,8 @@ int zstd_compressor_create(const sqfs_compressor_config_t *cfg, if (zstd == NULL) return SQFS_ERROR_ALLOC; + sqfs_object_init(zstd, zstd_destroy, zstd_create_copy); + zstd->block_size = cfg->block_size; zstd->level = cfg->level; zstd->zctx = ZSTD_createCCtx(); @@ -164,8 +166,6 @@ int zstd_compressor_create(const sqfs_compressor_config_t *cfg, zstd_uncomp_block : zstd_comp_block; base->write_options = zstd_write_options; base->read_options = zstd_read_options; - ((sqfs_object_t *)base)->copy = zstd_create_copy; - ((sqfs_object_t *)base)->destroy = zstd_destroy; *out = base; return 0; diff --git a/lib/sqfs/data_reader.c b/lib/sqfs/data_reader.c index 1033db9..c3fc1b9 100644 --- a/lib/sqfs/data_reader.c +++ b/lib/sqfs/data_reader.c @@ -196,14 +196,14 @@ sqfs_data_reader_t *sqfs_data_reader_create(sqfs_file_t *file, if (data == NULL) return NULL; + sqfs_object_init(data, data_reader_destroy, data_reader_copy); + data->frag_tbl = sqfs_frag_table_create(0); if (data->frag_tbl == NULL) { free(data); return NULL; } - ((sqfs_object_t *)data)->destroy = data_reader_destroy; - ((sqfs_object_t *)data)->copy = data_reader_copy; data->file = file; data->block_size = block_size; data->cmp = cmp; diff --git a/lib/sqfs/dir_reader/dir_reader.c b/lib/sqfs/dir_reader/dir_reader.c index 68cebd3..38700df 100644 --- a/lib/sqfs/dir_reader/dir_reader.c +++ b/lib/sqfs/dir_reader/dir_reader.c @@ -122,6 +122,8 @@ sqfs_dir_reader_t *sqfs_dir_reader_create(const sqfs_super_t *super, if (rd == NULL) return NULL; + sqfs_object_init(rd, dir_reader_destroy, dir_reader_copy); + if (flags & SQFS_DIR_READER_DOT_ENTRIES) { ret = rbtree_init(&rd->dcache, sizeof(sqfs_u32), sizeof(sqfs_u64), dcache_key_compare); @@ -150,8 +152,6 @@ sqfs_dir_reader_t *sqfs_dir_reader_create(const sqfs_super_t *super, if (rd->meta_dir == NULL) goto fail_mdir; - ((sqfs_object_t *)rd)->destroy = dir_reader_destroy; - ((sqfs_object_t *)rd)->copy = dir_reader_copy; rd->super = super; rd->flags = flags; rd->state = DIR_STATE_NONE; diff --git a/lib/sqfs/dir_writer.c b/lib/sqfs/dir_writer.c index ce63a1e..f56e0a7 100644 --- a/lib/sqfs/dir_writer.c +++ b/lib/sqfs/dir_writer.c @@ -147,6 +147,8 @@ sqfs_dir_writer_t *sqfs_dir_writer_create(sqfs_meta_writer_t *dm, if (writer == NULL) return NULL; + sqfs_object_init(writer, dir_writer_destroy, NULL); + if (flags & SQFS_DIR_WRITER_CREATE_EXPORT_TABLE) { if (array_init(&writer->export_tbl, sizeof(sqfs_u64), 512)) { free(writer); @@ -157,7 +159,6 @@ sqfs_dir_writer_t *sqfs_dir_writer_create(sqfs_meta_writer_t *dm, writer->export_tbl.size * writer->export_tbl.count); } - ((sqfs_object_t *)writer)->destroy = dir_writer_destroy; writer->dm = dm; return writer; } diff --git a/lib/sqfs/frag_table.c b/lib/sqfs/frag_table.c index 71627df..151df28 100644 --- a/lib/sqfs/frag_table.c +++ b/lib/sqfs/frag_table.c @@ -59,9 +59,9 @@ sqfs_frag_table_t *sqfs_frag_table_create(sqfs_u32 flags) if (tbl == NULL) return NULL; + sqfs_object_init(tbl, frag_table_destroy, frag_table_copy); + array_init(&tbl->table, sizeof(sqfs_fragment_t), 0); - ((sqfs_object_t *)tbl)->copy = frag_table_copy; - ((sqfs_object_t *)tbl)->destroy = frag_table_destroy; return tbl; } diff --git a/lib/sqfs/id_table.c b/lib/sqfs/id_table.c index cebf64b..ec3fdfe 100644 --- a/lib/sqfs/id_table.c +++ b/lib/sqfs/id_table.c @@ -58,9 +58,7 @@ sqfs_id_table_t *sqfs_id_table_create(sqfs_u32 flags) if (tbl != NULL) { array_init(&tbl->ids, sizeof(sqfs_u32), 0); - - ((sqfs_object_t *)tbl)->destroy = id_table_destroy; - ((sqfs_object_t *)tbl)->copy = id_table_copy; + sqfs_object_init(tbl, id_table_destroy, id_table_copy); } return tbl; diff --git a/lib/sqfs/meta_reader.c b/lib/sqfs/meta_reader.c index cddcda6..1b48fb8 100644 --- a/lib/sqfs/meta_reader.c +++ b/lib/sqfs/meta_reader.c @@ -74,8 +74,8 @@ sqfs_meta_reader_t *sqfs_meta_reader_create(sqfs_file_t *file, if (m == NULL) return NULL; - ((sqfs_object_t *)m)->copy = meta_reader_copy; - ((sqfs_object_t *)m)->destroy = meta_reader_destroy; + sqfs_object_init(m, meta_reader_destroy, meta_reader_copy); + m->block_offset = 0xFFFFFFFFFFFFFFFFUL; m->start = start; m->limit = limit; diff --git a/lib/sqfs/meta_writer.c b/lib/sqfs/meta_writer.c index 2314e06..5b8898b 100644 --- a/lib/sqfs/meta_writer.c +++ b/lib/sqfs/meta_writer.c @@ -87,7 +87,8 @@ 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; + sqfs_object_init(m, meta_writer_destroy, NULL); + m->cmp = cmp; m->file = file; m->flags = flags; diff --git a/lib/sqfs/unix/io_file.c b/lib/sqfs/unix/io_file.c index d4c1232..e1fb9db 100644 --- a/lib/sqfs/unix/io_file.c +++ b/lib/sqfs/unix/io_file.c @@ -154,6 +154,8 @@ sqfs_file_t *sqfs_open_file(const char *filename, sqfs_u32 flags) if (file == NULL) return NULL; + sqfs_object_init(file, stdio_destroy, stdio_copy); + if (flags & SQFS_FILE_OPEN_READ_ONLY) { file->readonly = true; open_mode = O_RDONLY; @@ -190,7 +192,5 @@ sqfs_file_t *sqfs_open_file(const char *filename, sqfs_u32 flags) base->write_at = stdio_write_at; base->get_size = stdio_get_size; base->truncate = stdio_truncate; - ((sqfs_object_t *)base)->copy = stdio_copy; - ((sqfs_object_t *)base)->destroy = stdio_destroy; return base; } diff --git a/lib/sqfs/win32/io_file.c b/lib/sqfs/win32/io_file.c index cfef296..548a246 100644 --- a/lib/sqfs/win32/io_file.c +++ b/lib/sqfs/win32/io_file.c @@ -187,6 +187,8 @@ sqfs_file_t *sqfs_open_file(const char *filename, sqfs_u32 flags) return NULL; } + sqfs_object_init(file, stdio_destroy, stdio_copy); + if (flags & SQFS_FILE_OPEN_READ_ONLY) { file->readonly = true; access_flags = GENERIC_READ; @@ -231,7 +233,5 @@ sqfs_file_t *sqfs_open_file(const char *filename, sqfs_u32 flags) base->write_at = stdio_write_at; base->get_size = stdio_get_size; base->truncate = stdio_truncate; - ((sqfs_object_t *)base)->destroy = stdio_destroy; - ((sqfs_object_t *)base)->copy = stdio_copy; return base; } diff --git a/lib/sqfs/xattr/xattr_reader.c b/lib/sqfs/xattr/xattr_reader.c index a55ad2f..313da88 100644 --- a/lib/sqfs/xattr/xattr_reader.c +++ b/lib/sqfs/xattr/xattr_reader.c @@ -347,7 +347,6 @@ sqfs_xattr_reader_t *sqfs_xattr_reader_create(sqfs_u32 flags) if (xr == NULL) return NULL; - ((sqfs_object_t *)xr)->copy = xattr_reader_copy; - ((sqfs_object_t *)xr)->destroy = xattr_reader_destroy; + sqfs_object_init(xr, xattr_reader_destroy, xattr_reader_copy); return xr; } diff --git a/lib/sqfs/xattr/xattr_writer.c b/lib/sqfs/xattr/xattr_writer.c index c49aaf1..39e1b05 100644 --- a/lib/sqfs/xattr/xattr_writer.c +++ b/lib/sqfs/xattr/xattr_writer.c @@ -95,6 +95,8 @@ sqfs_xattr_writer_t *sqfs_xattr_writer_create(sqfs_u32 flags) if (xwr == NULL) return NULL; + sqfs_object_init(xwr, xattr_writer_destroy, xattr_writer_copy); + if (str_table_init(&xwr->keys)) goto fail_keys; @@ -112,9 +114,6 @@ sqfs_xattr_writer_t *sqfs_xattr_writer_create(sqfs_u32 flags) } xwr->kv_block_tree.key_context = xwr; - - ((sqfs_object_t *)xwr)->copy = xattr_writer_copy; - ((sqfs_object_t *)xwr)->destroy = xattr_writer_destroy; return xwr; fail_tree: array_cleanup(&xwr->kv_pairs); |