From 4160b50a0b4c51f8b7191928cdf38d9fb0147fe2 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 4 Dec 2022 00:39:47 +0100 Subject: Add a helper function to initialize libsquashfs objects Signed-off-by: David Oberhollenzer --- lib/io/unix/istream.c | 8 ++++---- lib/io/unix/ostream.c | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'lib/io/unix') 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"); -- cgit v1.2.3