summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2019-12-18 10:00:29 +0200
committerTimo Teräs <timo.teras@iki.fi>2019-12-18 10:00:29 +0200
commit6996b1ea7504b1d3c90fbe6a6d4dee162fcff683 (patch)
treef1d94dd7e9e0709d068073c7ab6f5a97c7b8bb5d /src
parent695a2f8231f11f690ba96d6c4b537e22dd6571fd (diff)
downloadapk-tools-6996b1ea7504b1d3c90fbe6a6d4dee162fcff683.tar.gz
apk-tools-6996b1ea7504b1d3c90fbe6a6d4dee162fcff683.tar.bz2
apk-tools-6996b1ea7504b1d3c90fbe6a6d4dee162fcff683.tar.xz
apk-tools-6996b1ea7504b1d3c90fbe6a6d4dee162fcff683.zip
io: use proper base struct types for method implementations
Diffstat (limited to 'src')
-rw-r--r--src/apk_io.h22
-rw-r--r--src/archive.c12
-rw-r--r--src/gunzip.c25
-rw-r--r--src/io.c83
-rw-r--r--src/url.c12
5 files changed, 68 insertions, 86 deletions
diff --git a/src/apk_io.h b/src/apk_io.h
index 26c3f28..c44ed55 100644
--- a/src/apk_io.h
+++ b/src/apk_io.h
@@ -53,10 +53,14 @@ struct apk_file_info {
struct apk_xattr_array *xattrs;
};
+struct apk_istream;
+struct apk_bstream;
+struct apk_ostream;
+
struct apk_istream_ops {
- void (*get_meta)(void *stream, struct apk_file_meta *meta);
- ssize_t (*read)(void *stream, void *ptr, size_t size);
- void (*close)(void *stream);
+ void (*get_meta)(struct apk_istream *is, struct apk_file_meta *meta);
+ ssize_t (*read)(struct apk_istream *is, void *ptr, size_t size);
+ void (*close)(struct apk_istream *is);
};
struct apk_istream {
@@ -67,9 +71,9 @@ struct apk_istream {
#define APK_BSTREAM_EOF 0x0002
struct apk_bstream_ops {
- void (*get_meta)(void *stream, struct apk_file_meta *meta);
- apk_blob_t (*read)(void *stream, apk_blob_t token);
- void (*close)(void *stream, size_t *size);
+ void (*get_meta)(struct apk_bstream *bs, struct apk_file_meta *meta);
+ apk_blob_t (*read)(struct apk_bstream *bs, apk_blob_t token);
+ void (*close)(struct apk_bstream *bs, size_t *size);
};
struct apk_bstream {
@@ -78,8 +82,8 @@ struct apk_bstream {
};
struct apk_ostream_ops {
- ssize_t (*write)(void *stream, const void *buf, size_t size);
- int (*close)(void *stream);
+ ssize_t (*write)(struct apk_ostream *os, const void *buf, size_t size);
+ int (*close)(struct apk_ostream *os);
};
struct apk_ostream {
@@ -110,7 +114,7 @@ struct apk_istream *apk_istream_from_url_gz(const char *url);
ssize_t apk_istream_skip(struct apk_istream *istream, size_t size);
#define APK_SPLICE_ALL 0xffffffff
-ssize_t apk_istream_splice(void *stream, int fd, size_t size,
+ssize_t apk_istream_splice(struct apk_istream *is, int fd, size_t size,
apk_progress_cb cb, void *cb_ctx);
static inline struct apk_istream *apk_istream_from_fd(int fd)
diff --git a/src/archive.c b/src/archive.c
index 86f2e3d..e04e583 100644
--- a/src/archive.c
+++ b/src/archive.c
@@ -89,20 +89,18 @@ struct apk_tar_entry_istream {
time_t mtime;
};
-static void tar_entry_get_meta(void *stream, struct apk_file_meta *meta)
+static void tar_entry_get_meta(struct apk_istream *is, struct apk_file_meta *meta)
{
- struct apk_tar_entry_istream *teis =
- container_of(stream, struct apk_tar_entry_istream, is);
+ struct apk_tar_entry_istream *teis = container_of(is, struct apk_tar_entry_istream, is);
*meta = (struct apk_file_meta) {
.atime = teis->mtime,
.mtime = teis->mtime,
};
}
-static ssize_t tar_entry_read(void *stream, void *ptr, size_t size)
+static ssize_t tar_entry_read(struct apk_istream *is, void *ptr, size_t size)
{
- struct apk_tar_entry_istream *teis =
- container_of(stream, struct apk_tar_entry_istream, is);
+ struct apk_tar_entry_istream *teis = container_of(is, struct apk_tar_entry_istream, is);
ssize_t r;
if (size > teis->bytes_left)
@@ -131,7 +129,7 @@ static ssize_t tar_entry_read(void *stream, void *ptr, size_t size)
return r;
}
-static void tar_entry_close(void *stream)
+static void tar_entry_close(struct apk_istream *is)
{
}
diff --git a/src/gunzip.c b/src/gunzip.c
index 2de841b..5d96c7e 100644
--- a/src/gunzip.c
+++ b/src/gunzip.c
@@ -30,10 +30,9 @@ struct apk_gzip_istream {
apk_blob_t cbarg;
};
-static void gzi_get_meta(void *stream, struct apk_file_meta *meta)
+static void gzi_get_meta(struct apk_istream *is, struct apk_file_meta *meta)
{
- struct apk_gzip_istream *gis =
- container_of(stream, struct apk_gzip_istream, is);
+ struct apk_gzip_istream *gis = container_of(is, struct apk_gzip_istream, is);
apk_bstream_get_meta(gis->bs, meta);
}
@@ -47,10 +46,9 @@ static int gzi_boundary_change(struct apk_gzip_istream *gis)
return r;
}
-static ssize_t gzi_read(void *stream, void *ptr, size_t size)
+static ssize_t gzi_read(struct apk_istream *is, void *ptr, size_t size)
{
- struct apk_gzip_istream *gis =
- container_of(stream, struct apk_gzip_istream, is);
+ struct apk_gzip_istream *gis = container_of(is, struct apk_gzip_istream, is);
int r;
if (gis->err != 0) {
@@ -134,10 +132,9 @@ ret:
return size - gis->zs.avail_out;
}
-static void gzi_close(void *stream)
+static void gzi_close(struct apk_istream *is)
{
- struct apk_gzip_istream *gis =
- container_of(stream, struct apk_gzip_istream, is);
+ struct apk_gzip_istream *gis = container_of(is, struct apk_gzip_istream, is);
inflateEnd(&gis->zs);
apk_bstream_close(gis->bs, NULL);
@@ -184,9 +181,9 @@ struct apk_gzip_ostream {
z_stream zs;
};
-static ssize_t gzo_write(void *stream, const void *ptr, size_t size)
+static ssize_t gzo_write(struct apk_ostream *os, const void *ptr, size_t size)
{
- struct apk_gzip_ostream *gos = (struct apk_gzip_ostream *) stream;
+ struct apk_gzip_ostream *gos = container_of(os, struct apk_gzip_ostream, os);
unsigned char buffer[1024];
ssize_t have, r;
@@ -209,9 +206,9 @@ static ssize_t gzo_write(void *stream, const void *ptr, size_t size)
return size;
}
-static int gzo_close(void *stream)
+static int gzo_close(struct apk_ostream *os)
{
- struct apk_gzip_ostream *gos = (struct apk_gzip_ostream *) stream;
+ struct apk_gzip_ostream *gos = container_of(os, struct apk_gzip_ostream, os);
unsigned char buffer[1024];
size_t have;
int r, rc = 0;
@@ -229,7 +226,7 @@ static int gzo_close(void *stream)
rc = r;
deflateEnd(&gos->zs);
- free(stream);
+ free(gos);
return rc;
}
diff --git a/src/io.c b/src/io.c
index 382fd1b..d210109 100644
--- a/src/io.c
+++ b/src/io.c
@@ -63,17 +63,15 @@ struct apk_fd_istream {
int (*translate_status)(int status);
};
-static void fdi_get_meta(void *stream, struct apk_file_meta *meta)
+static void fdi_get_meta(struct apk_istream *is, struct apk_file_meta *meta)
{
- struct apk_fd_istream *fis =
- container_of(stream, struct apk_fd_istream, is);
+ struct apk_fd_istream *fis = container_of(is, struct apk_fd_istream, is);
apk_file_meta_from_fd(fis->fd, meta);
}
-static ssize_t fdi_read(void *stream, void *ptr, size_t size)
+static ssize_t fdi_read(struct apk_istream *is, void *ptr, size_t size)
{
- struct apk_fd_istream *fis =
- container_of(stream, struct apk_fd_istream, is);
+ struct apk_fd_istream *fis = container_of(is, struct apk_fd_istream, is);
ssize_t i = 0, r;
if (ptr == NULL) {
@@ -100,10 +98,9 @@ static ssize_t fdi_read(void *stream, void *ptr, size_t size)
return i;
}
-static void fdi_close(void *stream)
+static void fdi_close(struct apk_istream *is)
{
- struct apk_fd_istream *fis =
- container_of(stream, struct apk_fd_istream, is);
+ struct apk_fd_istream *fis = container_of(is, struct apk_fd_istream, is);
int status;
close(fis->fd);
@@ -165,11 +162,10 @@ ssize_t apk_istream_skip(struct apk_istream *is, size_t size)
return done;
}
-ssize_t apk_istream_splice(void *stream, int fd, size_t size,
+ssize_t apk_istream_splice(struct apk_istream *is, int fd, size_t size,
apk_progress_cb cb, void *cb_ctx)
{
static void *splice_buffer = NULL;
- struct apk_istream *is = (struct apk_istream *) stream;
unsigned char *buf, *mmapbase = MAP_FAILED;
size_t bufsz, done = 0, togo;
ssize_t r;
@@ -234,17 +230,15 @@ struct apk_istream_bstream {
size_t size;
};
-static void is_bs_get_meta(void *stream, struct apk_file_meta *meta)
+static void is_bs_get_meta(struct apk_bstream *bs, struct apk_file_meta *meta)
{
- struct apk_istream_bstream *isbs =
- container_of(stream, struct apk_istream_bstream, bs);
+ struct apk_istream_bstream *isbs = container_of(bs, struct apk_istream_bstream, bs);
return apk_istream_get_meta(isbs->is, meta);
}
-static apk_blob_t is_bs_read(void *stream, apk_blob_t token)
+static apk_blob_t is_bs_read(struct apk_bstream *bs, apk_blob_t token)
{
- struct apk_istream_bstream *isbs =
- container_of(stream, struct apk_istream_bstream, bs);
+ struct apk_istream_bstream *isbs = container_of(bs, struct apk_istream_bstream, bs);
ssize_t size;
apk_blob_t ret;
@@ -296,10 +290,9 @@ ret:
return ret;
}
-static void is_bs_close(void *stream, size_t *size)
+static void is_bs_close(struct apk_bstream *bs, size_t *size)
{
- struct apk_istream_bstream *isbs =
- container_of(stream, struct apk_istream_bstream, bs);
+ struct apk_istream_bstream *isbs = container_of(bs, struct apk_istream_bstream, bs);
if (size != NULL)
*size = isbs->size;
@@ -341,17 +334,15 @@ struct apk_mmap_bstream {
apk_blob_t left;
};
-static void mmap_get_meta(void *stream, struct apk_file_meta *meta)
+static void mmap_get_meta(struct apk_bstream *bs, struct apk_file_meta *meta)
{
- struct apk_mmap_bstream *mbs =
- container_of(stream, struct apk_mmap_bstream, bs);
+ struct apk_mmap_bstream *mbs = container_of(bs, struct apk_mmap_bstream, bs);
return apk_file_meta_from_fd(mbs->fd, meta);
}
-static apk_blob_t mmap_read(void *stream, apk_blob_t token)
+static apk_blob_t mmap_read(struct apk_bstream *bs, apk_blob_t token)
{
- struct apk_mmap_bstream *mbs =
- container_of(stream, struct apk_mmap_bstream, bs);
+ struct apk_mmap_bstream *mbs = container_of(bs, struct apk_mmap_bstream, bs);
apk_blob_t ret;
if (!APK_BLOB_IS_NULL(token) && !APK_BLOB_IS_NULL(mbs->left)) {
@@ -366,10 +357,9 @@ static apk_blob_t mmap_read(void *stream, apk_blob_t token)
return ret;
}
-static void mmap_close(void *stream, size_t *size)
+static void mmap_close(struct apk_bstream *bs, size_t *size)
{
- struct apk_mmap_bstream *mbs =
- container_of(stream, struct apk_mmap_bstream, bs);
+ struct apk_mmap_bstream *mbs = container_of(bs, struct apk_mmap_bstream, bs);
if (size != NULL)
*size = mbs->size;
@@ -448,17 +438,15 @@ struct apk_tee_bstream {
void *cb_ctx;
};
-static void tee_get_meta(void *stream, struct apk_file_meta *meta)
+static void tee_get_meta(struct apk_bstream *bs, struct apk_file_meta *meta)
{
- struct apk_tee_bstream *tbs =
- container_of(stream, struct apk_tee_bstream, bs);
+ struct apk_tee_bstream *tbs = container_of(bs, struct apk_tee_bstream, bs);
apk_bstream_get_meta(tbs->inner_bs, meta);
}
-static apk_blob_t tee_read(void *stream, apk_blob_t token)
+static apk_blob_t tee_read(struct apk_bstream *bs, apk_blob_t token)
{
- struct apk_tee_bstream *tbs =
- container_of(stream, struct apk_tee_bstream, bs);
+ struct apk_tee_bstream *tbs = container_of(bs, struct apk_tee_bstream, bs);
apk_blob_t blob;
blob = apk_bstream_read(tbs->inner_bs, token);
@@ -470,11 +458,10 @@ static apk_blob_t tee_read(void *stream, apk_blob_t token)
return blob;
}
-static void tee_close(void *stream, size_t *size)
+static void tee_close(struct apk_bstream *bs, size_t *size)
{
struct apk_file_meta meta;
- struct apk_tee_bstream *tbs =
- container_of(stream, struct apk_tee_bstream, bs);
+ struct apk_tee_bstream *tbs = container_of(bs, struct apk_tee_bstream, bs);
if (tbs->copy_meta) {
apk_bstream_get_meta(tbs->inner_bs, &meta);
@@ -831,10 +818,9 @@ static ssize_t fdo_flush(struct apk_fd_ostream *fos)
return 0;
}
-static ssize_t fdo_write(void *stream, const void *ptr, size_t size)
+static ssize_t fdo_write(struct apk_ostream *os, const void *ptr, size_t size)
{
- struct apk_fd_ostream *fos =
- container_of(stream, struct apk_fd_ostream, os);
+ struct apk_fd_ostream *fos = container_of(os, struct apk_fd_ostream, os);
ssize_t r;
if (size + fos->bytes >= sizeof(fos->buffer)) {
@@ -855,10 +841,9 @@ static ssize_t fdo_write(void *stream, const void *ptr, size_t size)
return size;
}
-static int fdo_close(void *stream)
+static int fdo_close(struct apk_ostream *os)
{
- struct apk_fd_ostream *fos =
- container_of(stream, struct apk_fd_ostream, os);
+ struct apk_fd_ostream *fos = container_of(os, struct apk_fd_ostream, os);
int rc;
fdo_flush(fos);
@@ -937,19 +922,17 @@ struct apk_counter_ostream {
off_t *counter;
};
-static ssize_t co_write(void *stream, const void *ptr, size_t size)
+static ssize_t co_write(struct apk_ostream *os, const void *ptr, size_t size)
{
- struct apk_counter_ostream *cos =
- container_of(stream, struct apk_counter_ostream, os);
+ struct apk_counter_ostream *cos = container_of(os, struct apk_counter_ostream, os);
*cos->counter += size;
return size;
}
-static int co_close(void *stream)
+static int co_close(struct apk_ostream *os)
{
- struct apk_counter_ostream *cos =
- container_of(stream, struct apk_counter_ostream, os);
+ struct apk_counter_ostream *cos = container_of(os, struct apk_counter_ostream, os);
free(cos);
return 0;
diff --git a/src/url.c b/src/url.c
index 414a109..cacca81 100644
--- a/src/url.c
+++ b/src/url.c
@@ -67,9 +67,9 @@ static int fetch_maperror(int ec)
return map[ec];
}
-static void fetch_get_meta(void *stream, struct apk_file_meta *meta)
+static void fetch_get_meta(struct apk_istream *is, struct apk_file_meta *meta)
{
- struct apk_fetch_istream *fis = container_of(stream, struct apk_fetch_istream, is);
+ struct apk_fetch_istream *fis = container_of(is, struct apk_fetch_istream, is);
*meta = (struct apk_file_meta) {
.atime = fis->urlstat.atime,
@@ -77,9 +77,9 @@ static void fetch_get_meta(void *stream, struct apk_file_meta *meta)
};
}
-static ssize_t fetch_read(void *stream, void *ptr, size_t size)
+static ssize_t fetch_read(struct apk_istream *is, void *ptr, size_t size)
{
- struct apk_fetch_istream *fis = container_of(stream, struct apk_fetch_istream, is);
+ struct apk_fetch_istream *fis = container_of(is, struct apk_fetch_istream, is);
ssize_t i = 0, r;
if (ptr == NULL) return apk_istream_skip(&fis->is, size);
@@ -94,9 +94,9 @@ static ssize_t fetch_read(void *stream, void *ptr, size_t size)
return i;
}
-static void fetch_close(void *stream)
+static void fetch_close(struct apk_istream *is)
{
- struct apk_fetch_istream *fis = container_of(stream, struct apk_fetch_istream, is);
+ struct apk_fetch_istream *fis = container_of(is, struct apk_fetch_istream, is);
fetchIO_close(fis->fetchIO);
free(fis);