From 6b471bb614beaeadcfa08008918ef6a2d93ac7e0 Mon Sep 17 00:00:00 2001 From: Timo Teras Date: Thu, 16 Jul 2009 15:16:05 +0300 Subject: various: new style index generation change the index generation to do old index, or the new style index where package identity is sha1 of control block and it's contained within an .tar.gz to allow signing in future. --- src/io.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/io.c') diff --git a/src/io.c b/src/io.c index 26d51b9..c7846c9 100644 --- a/src/io.c +++ b/src/io.c @@ -578,6 +578,45 @@ struct apk_ostream *apk_ostream_to_file(const char *file, mode_t mode) return apk_ostream_to_fd(fd); } +struct apk_counter_ostream { + struct apk_ostream os; + off_t *counter; +}; + +static size_t co_write(void *stream, const void *ptr, size_t size) +{ + struct apk_counter_ostream *cos = + container_of(stream, struct apk_counter_ostream, os); + + *cos->counter += size; + return size; +} + +static void co_close(void *stream) +{ + struct apk_counter_ostream *cos = + container_of(stream, struct apk_counter_ostream, os); + + free(cos); +} + +struct apk_ostream *apk_ostream_counter(off_t *counter) +{ + struct apk_counter_ostream *cos; + + cos = malloc(sizeof(struct apk_counter_ostream)); + if (cos == NULL) + return NULL; + + *cos = (struct apk_counter_ostream) { + .os.write = co_write, + .os.close = co_close, + .counter = counter, + }; + + return &cos->os; +} + size_t apk_ostream_write_string(struct apk_ostream *os, const char *string) { size_t len; -- cgit v1.2.3-60-g2f50