diff options
| author | Charles.Forsyth <devnull@localhost> | 2006-12-22 21:39:35 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2006-12-22 21:39:35 +0000 |
| commit | 74a4d8c26dd3c1e9febcb717cfd6cb6512991a7a (patch) | |
| tree | c6e220ba61db3a6ea4052e6841296d829654e664 /os/boot/libflate/deflateblock.c | |
| parent | 46439007cf417cbd9ac8049bb4122c890097a0fa (diff) | |
20060303
Diffstat (limited to 'os/boot/libflate/deflateblock.c')
| -rw-r--r-- | os/boot/libflate/deflateblock.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/os/boot/libflate/deflateblock.c b/os/boot/libflate/deflateblock.c new file mode 100644 index 00000000..60af31db --- /dev/null +++ b/os/boot/libflate/deflateblock.c @@ -0,0 +1,55 @@ +#include "lib9.h" +#include <flate.h> + +typedef struct Block Block; + +struct Block +{ + uchar *pos; + uchar *limit; +}; + +static int +blread(void *vb, void *buf, int n) +{ + Block *b; + + b = vb; + if(n > b->limit - b->pos) + n = b->limit - b->pos; + memmove(buf, b->pos, n); + b->pos += n; + return n; +} + +static int +blwrite(void *vb, void *buf, int n) +{ + Block *b; + + b = vb; + + if(n > b->limit - b->pos) + n = b->limit - b->pos; + memmove(b->pos, buf, n); + b->pos += n; + return n; +} + +int +deflateblock(uchar *dst, int dsize, uchar *src, int ssize, int level, int debug) +{ + Block bd, bs; + int ok; + + bs.pos = src; + bs.limit = src + ssize; + + bd.pos = dst; + bd.limit = dst + dsize; + + ok = deflate(&bd, blwrite, &bs, blread, level, debug); + if(ok != FlateOk) + return ok; + return bd.pos - dst; +} |
