From: Martin Mares Date: Sat, 11 Dec 2004 11:51:35 +0000 (+0000) Subject: Moved the lizard-fb module to Sherlock library, because it's heavily X-Git-Tag: holmes-import~853 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=836f12855a6ccfa54e727867584f070e5c846f4a;p=libucw.git Moved the lizard-fb module to Sherlock library, because it's heavily dependent on the bucket types. The rest of LiZaRd should better remain in libucw, it's very useful outside Sherlock. --- diff --git a/lib/Makefile b/lib/Makefile index 1ae62a68..ff317b43 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -21,7 +21,7 @@ LIBUCW_MODS= \ db \ url \ mainloop exitstatus runcmd sighandler \ - lizard lizard-safe lizard-fb adler32 \ + lizard lizard-safe adler32 \ md5 md5hex \ base64 base224 \ sync diff --git a/lib/lizard-fb.c b/lib/lizard-fb.c deleted file mode 100644 index d356d0cd..00000000 --- a/lib/lizard-fb.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - * LiZaRd -- Reading and writing to a fastbuf - * - * (c) 2004, Robert Spalek - */ - -#include "lib/lib.h" -#include "lib/lizard.h" -#include "lib/bbuf.h" -#include "lib/fastbuf.h" -#include "sherlock/bucket.h" /* FIXME */ - -#include - -static uns liz_type; -static float liz_min_compr; - -static bb_t bb_in, bb_out; - -void -lizard_set_type(uns type, float min_compr) -{ - liz_type = type; - liz_min_compr = min_compr; -} - -int -lizard_bwrite(struct fastbuf *fb_out, byte *ptr_in, uns len_in) -{ - byte *ptr_out; - uns len_out; - uns type = liz_type; - if (type == BUCKET_TYPE_V33_LIZARD && liz_min_compr) - { - uns est_out = len_in * LIZARD_MAX_MULTIPLY + LIZARD_MAX_ADD + 16; - uns aval_out = bdirect_write_prepare(fb_out, &ptr_out); - if (aval_out < est_out) - { - bb_grow(&bb_out, est_out); - ptr_out = bb_out.ptr; - } - else - ptr_out += 16; - len_out = lizard_compress(ptr_in, len_in, ptr_out); - if (len_out + 8 > len_in * liz_min_compr) - { - type = BUCKET_TYPE_V33; - ptr_out = ptr_in; - len_out = len_in; - } - } - else - { - if (type == BUCKET_TYPE_V33_LIZARD) - type = BUCKET_TYPE_V33; - ptr_out = ptr_in; - len_out = len_in; - } - bputl(fb_out, type); - bputl(fb_out, len_out); - if (type == BUCKET_TYPE_V33_LIZARD) - { - bputl(fb_out, len_in); - bputl(fb_out, adler32(ptr_in, len_in)); - } - if (ptr_out == bb_out.ptr || ptr_out == ptr_in) - bwrite(fb_out, ptr_out, len_out); - else - bdirect_write_commit(fb_out, ptr_out + len_out); - return type; -} - -int -lizard_bbcopy_compress(struct fastbuf *fb_out, struct fastbuf *fb_in, uns len_in) -{ - byte *ptr_in; - uns i = bdirect_read_prepare(fb_in, &ptr_in); - if (i < len_in) - { - bb_grow(&bb_in, len_in); - bread(fb_in, bb_in.ptr, len_in); - ptr_in = bb_in.ptr; - } - else - bdirect_read_commit(fb_in, ptr_in + len_in); - return lizard_bwrite(fb_out, ptr_in, len_in); -} - -static int -decompress(struct lizard_buffer *liz_buf, byte *ptr_in, byte **ptr_out) -{ - uns orig_len = GET_U32(ptr_in); - uns orig_adler = GET_U32(ptr_in + 4); - ptr_in += 8; - *ptr_out = lizard_decompress_safe(ptr_in, liz_buf, orig_len); - if (!*ptr_out) - return -1; - if (adler32(*ptr_out, orig_len) != orig_adler) - { - errno = EINVAL; - return -1; - } - return orig_len; -} - -int -lizard_memread(struct lizard_buffer *liz_buf, byte *ptr_in, byte **ptr_out, uns *type) -{ - *type = GET_U32(ptr_in); - if (*type < BUCKET_TYPE_PLAIN || *type > BUCKET_TYPE_V33_LIZARD) - { - errno = EINVAL; - return -1; - } - uns stored_len = GET_U32(ptr_in + 4); - ptr_in += 8; - if (*type == BUCKET_TYPE_V33_LIZARD) - return decompress(liz_buf, ptr_in, ptr_out); - else - { - *ptr_out = ptr_in; - return stored_len; - } -} - -int -lizard_bread(struct lizard_buffer *liz_buf, struct fastbuf *fb_in, byte **ptr_out, uns *type) -{ - *type = bgetl(fb_in); - if (*type < BUCKET_TYPE_PLAIN || *type > BUCKET_TYPE_V33_LIZARD) - { - if (*type == ~0U) // EOF - errno = EBADF; - else - errno = EINVAL; - return -1; - } - uns stored_len = bgetl(fb_in); - uns want_len = stored_len + (*type == BUCKET_TYPE_V33_LIZARD ? 8 : 0); - byte *ptr_in; - uns i = bdirect_read_prepare(fb_in, &ptr_in); - if (i < want_len) - { - bb_grow(&bb_in, want_len); - bread(fb_in, bb_in.ptr, want_len); - ptr_in = bb_in.ptr; - } - else - bdirect_read_commit(fb_in, ptr_in + want_len); - if (*type == BUCKET_TYPE_V33_LIZARD) - return decompress(liz_buf, ptr_in, ptr_out); - else - { - *ptr_out = ptr_in; - return stored_len; - } -} diff --git a/lib/lizard.h b/lib/lizard.h index be8a0618..bc7f317e 100644 --- a/lib/lizard.h +++ b/lib/lizard.h @@ -46,14 +46,4 @@ adler32(byte *buf, uns len) return update_adler32(1, buf, len); } -/* lizard-fb.c */ -struct fastbuf; - -void lizard_set_type(uns type, float min_compr); -int lizard_bwrite(struct fastbuf *fb_out, byte *ptr_in, uns len_in); -int lizard_bbcopy_compress(struct fastbuf *fb_out, struct fastbuf *fb_in, uns len_in); -int lizard_memread(struct lizard_buffer *liz_buf, byte *ptr_in, byte **ptr_out, uns *type); -int lizard_bread(struct lizard_buffer *liz_buf, struct fastbuf *fb_in, byte **ptr_out, uns *type); - /* These functions use static variables, hence they are not re-entrant. */ - #endif