io: remove unused size parameter from bstream close
parent
e4aae45f96
commit
e39334e44f
|
@ -638,7 +638,7 @@ int main(int argc, char **argv)
|
||||||
struct apk_bstream *bs = apk_bstream_from_file(AT_FDCWD, test_installed_db);
|
struct apk_bstream *bs = apk_bstream_from_file(AT_FDCWD, test_installed_db);
|
||||||
if (!IS_ERR_OR_NULL(bs)) {
|
if (!IS_ERR_OR_NULL(bs)) {
|
||||||
apk_db_index_read(&db, bs, -1);
|
apk_db_index_read(&db, bs, -1);
|
||||||
apk_bstream_close(bs, NULL);
|
apk_bstream_close(bs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < test_repos->num; i++) {
|
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_db_index_read(&db, bs, repo);
|
||||||
apk_bstream_close(bs, NULL);
|
apk_bstream_close(bs);
|
||||||
if (repo != -2) {
|
if (repo != -2) {
|
||||||
if (!(apk_flags & APK_NO_NETWORK))
|
if (!(apk_flags & APK_NO_NETWORK))
|
||||||
db.available_repos |= BIT(repo);
|
db.available_repos |= BIT(repo);
|
||||||
|
|
|
@ -73,7 +73,7 @@ struct apk_istream {
|
||||||
struct apk_bstream_ops {
|
struct apk_bstream_ops {
|
||||||
void (*get_meta)(struct apk_bstream *bs, struct apk_file_meta *meta);
|
void (*get_meta)(struct apk_bstream *bs, struct apk_file_meta *meta);
|
||||||
apk_blob_t (*read)(struct apk_bstream *bs, apk_blob_t token);
|
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 {
|
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);
|
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);
|
struct apk_ostream *apk_ostream_to_fd(int fd);
|
||||||
|
|
|
@ -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);
|
bs = apk_bstream_from_file(db->root_fd, apk_installed_file);
|
||||||
if (!IS_ERR_OR_NULL(bs)) {
|
if (!IS_ERR_OR_NULL(bs)) {
|
||||||
r = apk_db_index_read(db, bs, -1);
|
r = apk_db_index_read(db, bs, -1);
|
||||||
apk_bstream_close(bs, NULL);
|
apk_bstream_close(bs);
|
||||||
if (r != 0) return -1;
|
if (r != 0) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bs = apk_bstream_from_file(db->root_fd, apk_triggers_file);
|
bs = apk_bstream_from_file(db->root_fd, apk_triggers_file);
|
||||||
if (!IS_ERR_OR_NULL(bs)) {
|
if (!IS_ERR_OR_NULL(bs)) {
|
||||||
apk_db_triggers_read(db, 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");
|
bs = apk_bstream_from_file(db->cache_fd, "installed");
|
||||||
if (!IS_ERR_OR_NULL(bs)) {
|
if (!IS_ERR_OR_NULL(bs)) {
|
||||||
apk_db_index_read(db, bs, -2);
|
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);
|
bs = apk_bstream_from_istream(is);
|
||||||
if (!IS_ERR_OR_NULL(bs)) {
|
if (!IS_ERR_OR_NULL(bs)) {
|
||||||
apk_db_index_read(ctx->db, bs, ctx->repo);
|
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));
|
bs = apk_bstream_from_istream(apk_bstream_gunzip(bs));
|
||||||
if (!IS_ERR_OR_NULL(bs)) {
|
if (!IS_ERR_OR_NULL(bs)) {
|
||||||
apk_db_index_read(db, bs, repo);
|
apk_db_index_read(db, bs, repo);
|
||||||
apk_bstream_close(bs, NULL);
|
apk_bstream_close(bs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
|
|
|
@ -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);
|
struct apk_gzip_istream *gis = container_of(is, struct apk_gzip_istream, is);
|
||||||
|
|
||||||
inflateEnd(&gis->zs);
|
inflateEnd(&gis->zs);
|
||||||
apk_bstream_close(gis->bs, NULL);
|
apk_bstream_close(gis->bs);
|
||||||
free(gis);
|
free(gis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ struct apk_istream *apk_bstream_gunzip_mpart(struct apk_bstream *bs,
|
||||||
|
|
||||||
return &gis->is;
|
return &gis->is;
|
||||||
err:
|
err:
|
||||||
apk_bstream_close(bs, NULL);
|
apk_bstream_close(bs);
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
54
src/io.c
54
src/io.c
|
@ -227,7 +227,6 @@ struct apk_istream_bstream {
|
||||||
struct apk_istream *is;
|
struct apk_istream *is;
|
||||||
apk_blob_t left;
|
apk_blob_t left;
|
||||||
char buffer[8*1024];
|
char buffer[8*1024];
|
||||||
size_t size;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void is_bs_get_meta(struct apk_bstream *bs, struct apk_file_meta *meta)
|
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,
|
size = apk_istream_read(isbs->is, isbs->buffer + isbs->left.len,
|
||||||
sizeof(isbs->buffer) - isbs->left.len);
|
sizeof(isbs->buffer) - isbs->left.len);
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
isbs->size += size;
|
|
||||||
isbs->left.len += size;
|
isbs->left.len += size;
|
||||||
} else if (size == 0) {
|
} else if (size == 0) {
|
||||||
if (isbs->left.len == 0)
|
if (isbs->left.len == 0)
|
||||||
|
@ -290,13 +288,10 @@ ret:
|
||||||
return 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);
|
struct apk_istream_bstream *isbs = container_of(bs, struct apk_istream_bstream, bs);
|
||||||
|
|
||||||
if (size != NULL)
|
|
||||||
*size = isbs->size;
|
|
||||||
|
|
||||||
apk_istream_close(isbs->is);
|
apk_istream_close(isbs->is);
|
||||||
free(isbs);
|
free(isbs);
|
||||||
}
|
}
|
||||||
|
@ -320,8 +315,7 @@ struct apk_bstream *apk_bstream_from_istream(struct apk_istream *istream)
|
||||||
.ops = &is_bstream_ops,
|
.ops = &is_bstream_ops,
|
||||||
};
|
};
|
||||||
isbs->is = istream;
|
isbs->is = istream;
|
||||||
isbs->left = APK_BLOB_PTR_LEN(isbs->buffer, 0),
|
isbs->left = APK_BLOB_PTR_LEN(isbs->buffer, 0);
|
||||||
isbs->size = 0;
|
|
||||||
|
|
||||||
return &isbs->bs;
|
return &isbs->bs;
|
||||||
}
|
}
|
||||||
|
@ -357,12 +351,10 @@ static apk_blob_t mmap_read(struct apk_bstream *bs, apk_blob_t token)
|
||||||
return ret;
|
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);
|
struct apk_mmap_bstream *mbs = container_of(bs, struct apk_mmap_bstream, bs);
|
||||||
|
|
||||||
if (size != NULL)
|
|
||||||
*size = mbs->size;
|
|
||||||
munmap(mbs->ptr, mbs->size);
|
munmap(mbs->ptr, mbs->size);
|
||||||
close(mbs->fd);
|
close(mbs->fd);
|
||||||
free(mbs);
|
free(mbs);
|
||||||
|
@ -391,14 +383,14 @@ static struct apk_bstream *apk_mmap_bstream_from_fd(int fd)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
mbs->bs = (struct apk_bstream) {
|
*mbs = (struct apk_mmap_bstream) {
|
||||||
.flags = APK_BSTREAM_SINGLE_READ,
|
.bs.flags = APK_BSTREAM_SINGLE_READ,
|
||||||
.ops = &mmap_bstream_ops,
|
.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;
|
return &mbs->bs;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +450,7 @@ static apk_blob_t tee_read(struct apk_bstream *bs, apk_blob_t token)
|
||||||
return blob;
|
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_file_meta meta;
|
||||||
struct apk_tee_bstream *tbs = container_of(bs, struct apk_tee_bstream, bs);
|
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_file_meta_to_fd(tbs->fd, &meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
apk_bstream_close(tbs->inner_bs, NULL);
|
apk_bstream_close(tbs->inner_bs);
|
||||||
if (size != NULL) *size = tbs->size;
|
|
||||||
close(tbs->fd);
|
close(tbs->fd);
|
||||||
free(tbs);
|
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);
|
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
r = errno;
|
r = errno;
|
||||||
apk_bstream_close(from, NULL);
|
apk_bstream_close(from);
|
||||||
return ERR_PTR(-r);
|
return ERR_PTR(-r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,19 +490,18 @@ struct apk_bstream *apk_bstream_tee(struct apk_bstream *from, int atfd, const ch
|
||||||
if (!tbs) {
|
if (!tbs) {
|
||||||
r = errno;
|
r = errno;
|
||||||
close(fd);
|
close(fd);
|
||||||
apk_bstream_close(from, NULL);
|
apk_bstream_close(from);
|
||||||
return ERR_PTR(-r);
|
return ERR_PTR(-r);
|
||||||
}
|
}
|
||||||
|
|
||||||
tbs->bs = (struct apk_bstream) {
|
*tbs = (struct apk_tee_bstream) {
|
||||||
.ops = &tee_bstream_ops,
|
.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;
|
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_DigestFinal_ex(mdctx, fi->csum.data, NULL);
|
||||||
EVP_MD_CTX_free(mdctx);
|
EVP_MD_CTX_free(mdctx);
|
||||||
}
|
}
|
||||||
apk_bstream_close(bs, NULL);
|
apk_bstream_close(bs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue