summaryrefslogtreecommitdiff
path: root/stream/filt_null.c
blob: 601ed8152288262b72e166bb6774d4916ea3f567 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "fitz-base.h"
#include "fitz-stream.h"

typedef struct fz_nullfilter_s fz_nullfilter;

struct fz_nullfilter_s
{
	fz_filter super;
	int len;
	int cur;
};

fz_error *
fz_newnullfilter(fz_filter **fp, int len)
{
	FZ_NEWFILTER(fz_nullfilter, f, nullfilter);
	f->len = len;
	f->cur = 0;
	return fz_okay;
}

void
fz_dropnullfilter(fz_filter *f)
{
}

fz_error *
fz_processnullfilter(fz_filter *filter, fz_buffer *in, fz_buffer *out)
{
	fz_nullfilter *f = (fz_nullfilter*)filter;
	int n;

	n = MIN(in->wp - in->rp, out->ep - out->wp);
	if (f->len >= 0)
	    n = MIN(n, f->len - f->cur);

	if (n)
	{
		memcpy(out->wp, in->rp, n);
		in->rp += n;
		out->wp += n;
		f->cur += n;
	}

	if (f->cur == f->len)
		return fz_iodone;
	if (in->rp == in->wp)
		return fz_ioneedin;
	if (out->wp == out->ep)
		return fz_ioneedout;

	return fz_throw("braindead programmer trapped in nullfilter");
}