aboutsummaryrefslogtreecommitdiff
path: root/lib/io
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-12-04 00:39:47 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-01-19 16:24:56 +0100
commit4160b50a0b4c51f8b7191928cdf38d9fb0147fe2 (patch)
tree996998b7fe506101c8d91aeb71891eaac358902e /lib/io
parent42194bf57d470e548e03c44f5c2340d7d23a3ecb (diff)
Add a helper function to initialize libsquashfs objects
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/io')
-rw-r--r--lib/io/compress/ostream_compressor.c6
-rw-r--r--lib/io/uncompress/istream_compressor.c6
-rw-r--r--lib/io/unix/istream.c8
-rw-r--r--lib/io/unix/ostream.c6
-rw-r--r--lib/io/win32/istream.c8
-rw-r--r--lib/io/win32/ostream.c6
6 files changed, 18 insertions, 22 deletions
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;
}