Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/planix-v0/sys/src/libflate/deflateblock.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
#include <flate.h>
4
 
5
typedef struct Block	Block;
6
 
7
struct Block
8
{
9
	uchar	*pos;
10
	uchar	*limit;
11
};
12
 
13
static int
14
blread(void *vb, void *buf, int n)
15
{
16
	Block *b;
17
 
18
	b = vb;
19
	if(n > b->limit - b->pos)
20
		n = b->limit - b->pos;
21
	memmove(buf, b->pos, n);
22
	b->pos += n;
23
	return n;
24
}
25
 
26
static int
27
blwrite(void *vb, void *buf, int n)
28
{
29
	Block *b;
30
 
31
	b = vb;
32
 
33
	if(n > b->limit - b->pos)
34
		n = b->limit - b->pos;
35
	memmove(b->pos, buf, n);
36
	b->pos += n;
37
	return n;
38
}
39
 
40
int
41
deflateblock(uchar *dst, int dsize, uchar *src, int ssize, int level, int debug)
42
{
43
	Block bd, bs;
44
	int ok;
45
 
46
	bs.pos = src;
47
	bs.limit = src + ssize;
48
 
49
	bd.pos = dst;
50
	bd.limit = dst + dsize;
51
 
52
	ok = deflate(&bd, blwrite, &bs, blread, level, debug);
53
	if(ok != FlateOk)
54
		return ok;
55
	return bd.pos - dst;
56
}