summaryrefslogtreecommitdiff
path: root/fitz/filt_copy.c
blob: 6c77ff17191dac033d542062fa4175bad0f3f809 (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
#include "fitz_base.h"
#include "fitz_stream.h"

typedef struct fz_copyfilter_s fz_copyfilter;

struct fz_copyfilter_s
{
	fz_filter super;
};

fz_error
fz_newcopyfilter(fz_filter **fp)
{
    FZ_NEWFILTER(fz_copyfilter, f, copyfilter);
    return fz_okay;
}

void
fz_dropcopyfilter(fz_filter *f)
{
}

fz_error
fz_processcopyfilter(fz_filter *filter, fz_buffer *in, fz_buffer *out)
{
    int n;

    while (1)
    {
	if (in->rp + 1 > in->wp)
	{
	    if (in->eof)
		return fz_iodone;
	    return fz_ioneedin;
	}

	if (out->wp + 1 > out->ep)
	    return fz_ioneedout;

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