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/inflateblock.c | |
| parent | 46439007cf417cbd9ac8049bb4122c890097a0fa (diff) | |
20060303
Diffstat (limited to 'os/boot/libflate/inflateblock.c')
| -rw-r--r-- | os/boot/libflate/inflateblock.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/os/boot/libflate/inflateblock.c b/os/boot/libflate/inflateblock.c new file mode 100644 index 00000000..864bdeca --- /dev/null +++ b/os/boot/libflate/inflateblock.c @@ -0,0 +1,53 @@ +#include "lib9.h" +#include <flate.h> + +typedef struct Block Block; + +struct Block +{ + uchar *pos; + uchar *limit; +}; + +static int +blgetc(void *vb) +{ + Block *b; + + b = vb; + if(b->pos >= b->limit) + return -1; + return *b->pos++; +} + +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 +inflateblock(uchar *dst, int dsize, uchar *src, int ssize) +{ + Block bd, bs; + int ok; + + bs.pos = src; + bs.limit = src + ssize; + + bd.pos = dst; + bd.limit = dst + dsize; + + ok = inflate(&bd, blwrite, &bs, blgetc); + if(ok != FlateOk) + return ok; + return bd.pos - dst; +} |
