diff options
-rw-r--r-- | src/apk.c | 4 | ||||
-rw-r--r-- | src/apk_io.h | 6 | ||||
-rw-r--r-- | src/database.c | 10 | ||||
-rw-r--r-- | src/gunzip.c | 4 | ||||
-rw-r--r-- | src/io.c | 54 |
5 files changed, 34 insertions, 44 deletions
@@ -638,7 +638,7 @@ int main(int argc, char **argv) struct apk_bstream *bs = apk_bstream_from_file(AT_FDCWD, test_installed_db); if (!IS_ERR_OR_NULL(bs)) { apk_db_index_read(&db, bs, -1); - apk_bstream_close(bs, NULL); + apk_bstream_close(bs); } } for (i = 0; i < test_repos->num; i++) { @@ -666,7 +666,7 @@ int main(int argc, char **argv) } apk_db_index_read(&db, bs, repo); - apk_bstream_close(bs, NULL); + apk_bstream_close(bs); if (repo != -2) { if (!(apk_flags & APK_NO_NETWORK)) db.available_repos |= BIT(repo); diff --git a/src/apk_io.h b/src/apk_io.h index c44ed55..cfe4a29 100644 --- a/src/apk_io.h +++ b/src/apk_io.h @@ -73,7 +73,7 @@ struct apk_istream { struct apk_bstream_ops { 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); + void (*close)(struct apk_bstream *bs); }; struct apk_bstream { @@ -178,9 +178,9 @@ static inline apk_blob_t apk_bstream_read(struct apk_bstream *bs, apk_blob_t tok { return bs->ops->read(bs, token); } -static inline void apk_bstream_close(struct apk_bstream *bs, size_t *size) +static inline void apk_bstream_close(struct apk_bstream *bs) { - bs->ops->close(bs, size); + bs->ops->close(bs); } struct apk_ostream *apk_ostream_to_fd(int fd); diff --git a/src/database.c b/src/database.c index 1af6b9d..bbf6327 100644 --- a/src/database.c +++ b/src/database.c @@ -1164,14 +1164,14 @@ static int apk_db_read_state(struct apk_database *db, int flags) bs = apk_bstream_from_file(db->root_fd, apk_installed_file); if (!IS_ERR_OR_NULL(bs)) { r = apk_db_index_read(db, bs, -1); - apk_bstream_close(bs, NULL); + apk_bstream_close(bs); if (r != 0) return -1; } bs = apk_bstream_from_file(db->root_fd, apk_triggers_file); if (!IS_ERR_OR_NULL(bs)) { apk_db_triggers_read(db, bs); - apk_bstream_close(bs, NULL); + apk_bstream_close(bs); } } @@ -1685,7 +1685,7 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts) bs = apk_bstream_from_file(db->cache_fd, "installed"); if (!IS_ERR_OR_NULL(bs)) { apk_db_index_read(db, bs, -2); - apk_bstream_close(bs, NULL); + apk_bstream_close(bs); } } } @@ -2182,7 +2182,7 @@ static int load_apkindex(void *sctx, const struct apk_file_info *fi, bs = apk_bstream_from_istream(is); if (!IS_ERR_OR_NULL(bs)) { apk_db_index_read(ctx->db, bs, ctx->repo); - apk_bstream_close(bs, NULL); + apk_bstream_close(bs); } } @@ -2215,7 +2215,7 @@ static int load_index(struct apk_database *db, struct apk_bstream *bs, bs = apk_bstream_from_istream(apk_bstream_gunzip(bs)); if (!IS_ERR_OR_NULL(bs)) { apk_db_index_read(db, bs, repo); - apk_bstream_close(bs, NULL); + apk_bstream_close(bs); } } return r; diff --git a/src/gunzip.c b/src/gunzip.c index 5d96c7e..2c35c5b 100644 --- a/src/gunzip.c +++ b/src/gunzip.c @@ -137,7 +137,7 @@ static void gzi_close(struct apk_istream *is) struct apk_gzip_istream *gis = container_of(is, struct apk_gzip_istream, is); inflateEnd(&gis->zs); - apk_bstream_close(gis->bs, NULL); + apk_bstream_close(gis->bs); free(gis); } @@ -171,7 +171,7 @@ struct apk_istream *apk_bstream_gunzip_mpart(struct apk_bstream *bs, return &gis->is; err: - apk_bstream_close(bs, NULL); + apk_bstream_close(bs); return ERR_PTR(-ENOMEM); } @@ -227,7 +227,6 @@ struct apk_istream_bstream { struct apk_istream *is; apk_blob_t left; char buffer[8*1024]; - size_t size; }; static void is_bs_get_meta(struct apk_bstream *bs, struct apk_file_meta *meta) @@ -263,7 +262,6 @@ static apk_blob_t is_bs_read(struct apk_bstream *bs, apk_blob_t token) size = apk_istream_read(isbs->is, isbs->buffer + isbs->left.len, sizeof(isbs->buffer) - isbs->left.len); if (size > 0) { - isbs->size += size; isbs->left.len += size; } else if (size == 0) { if (isbs->left.len == 0) @@ -290,13 +288,10 @@ ret: return ret; } -static void is_bs_close(struct apk_bstream *bs, size_t *size) +static void is_bs_close(struct apk_bstream *bs) { struct apk_istream_bstream *isbs = container_of(bs, struct apk_istream_bstream, bs); - if (size != NULL) - *size = isbs->size; - apk_istream_close(isbs->is); free(isbs); } @@ -320,8 +315,7 @@ struct apk_bstream *apk_bstream_from_istream(struct apk_istream *istream) .ops = &is_bstream_ops, }; isbs->is = istream; - isbs->left = APK_BLOB_PTR_LEN(isbs->buffer, 0), - isbs->size = 0; + isbs->left = APK_BLOB_PTR_LEN(isbs->buffer, 0); return &isbs->bs; } @@ -357,12 +351,10 @@ static apk_blob_t mmap_read(struct apk_bstream *bs, apk_blob_t token) return ret; } -static void mmap_close(struct apk_bstream *bs, size_t *size) +static void mmap_close(struct apk_bstream *bs) { struct apk_mmap_bstream *mbs = container_of(bs, struct apk_mmap_bstream, bs); - if (size != NULL) - *size = mbs->size; munmap(mbs->ptr, mbs->size); close(mbs->fd); free(mbs); @@ -391,14 +383,14 @@ static struct apk_bstream *apk_mmap_bstream_from_fd(int fd) return ERR_PTR(-ENOMEM); } - mbs->bs = (struct apk_bstream) { - .flags = APK_BSTREAM_SINGLE_READ, - .ops = &mmap_bstream_ops, + *mbs = (struct apk_mmap_bstream) { + .bs.flags = APK_BSTREAM_SINGLE_READ, + .bs.ops = &mmap_bstream_ops, + .fd = fd, + .size = st.st_size, + .ptr = ptr, + .left = APK_BLOB_PTR_LEN(ptr, st.st_size), }; - mbs->fd = fd; - mbs->size = st.st_size; - mbs->ptr = ptr; - mbs->left = APK_BLOB_PTR_LEN(ptr, mbs->size); return &mbs->bs; } @@ -458,7 +450,7 @@ static apk_blob_t tee_read(struct apk_bstream *bs, apk_blob_t token) return blob; } -static void tee_close(struct apk_bstream *bs, size_t *size) +static void tee_close(struct apk_bstream *bs) { struct apk_file_meta meta; struct apk_tee_bstream *tbs = container_of(bs, struct apk_tee_bstream, bs); @@ -468,8 +460,7 @@ static void tee_close(struct apk_bstream *bs, size_t *size) apk_file_meta_to_fd(tbs->fd, &meta); } - apk_bstream_close(tbs->inner_bs, NULL); - if (size != NULL) *size = tbs->size; + apk_bstream_close(tbs->inner_bs); close(tbs->fd); free(tbs); } @@ -491,7 +482,7 @@ struct apk_bstream *apk_bstream_tee(struct apk_bstream *from, int atfd, const ch S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd < 0) { r = errno; - apk_bstream_close(from, NULL); + apk_bstream_close(from); return ERR_PTR(-r); } @@ -499,19 +490,18 @@ struct apk_bstream *apk_bstream_tee(struct apk_bstream *from, int atfd, const ch if (!tbs) { r = errno; close(fd); - apk_bstream_close(from, NULL); + apk_bstream_close(from); return ERR_PTR(-r); } - tbs->bs = (struct apk_bstream) { - .ops = &tee_bstream_ops, + *tbs = (struct apk_tee_bstream) { + .bs.ops = &tee_bstream_ops, + .inner_bs = from, + .fd = fd, + .copy_meta = copy_meta, + .cb = cb, + .cb_ctx = cb_ctx, }; - tbs->inner_bs = from; - tbs->fd = fd; - tbs->copy_meta = copy_meta; - tbs->size = 0; - tbs->cb = cb; - tbs->cb_ctx = cb_ctx; return &tbs->bs; } @@ -728,7 +718,7 @@ int apk_fileinfo_get(int atfd, const char *filename, unsigned int flags, EVP_DigestFinal_ex(mdctx, fi->csum.data, NULL); EVP_MD_CTX_free(mdctx); } - apk_bstream_close(bs, NULL); + apk_bstream_close(bs); } } |