blob: e70a4580a8bc147f32f1202504c2d0af26a5a2dc (
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#include "fitz.h"
static fz_stream *
fz_newstream(int kind)
{
fz_stream *stm;
stm = fz_malloc(sizeof(fz_stream));
stm->refs = 1;
stm->kind = kind;
stm->dead = 0;
stm->error = fz_okay;
stm->buffer = nil;
stm->chain = nil;
stm->filter = nil;
stm->file = -1;
return stm;
}
fz_stream *
fz_keepstream(fz_stream *stm)
{
stm->refs ++;
return stm;
}
void
fz_dropstream(fz_stream *stm)
{
stm->refs --;
if (stm->refs == 0)
{
if (stm->error)
{
fz_catch(stm->error, "dropped unhandled ioerror");
stm->error = fz_okay;
}
switch (stm->kind)
{
case FZ_SFILE:
close(stm->file);
break;
case FZ_SFILTER:
fz_dropfilter(stm->filter);
fz_dropstream(stm->chain);
break;
case FZ_SBUFFER:
break;
}
fz_dropbuffer(stm->buffer);
fz_free(stm);
}
}
fz_stream *
fz_openfile(int fd)
{
fz_stream *stm;
stm = fz_newstream(FZ_SFILE);
stm->buffer = fz_newbuffer(FZ_BUFSIZE);
stm->file = fd;
return stm;
}
fz_stream *
fz_openfilter(fz_filter *flt, fz_stream *src)
{
fz_stream *stm;
stm = fz_newstream(FZ_SFILTER);
stm->buffer = fz_newbuffer(FZ_BUFSIZE);
stm->chain = fz_keepstream(src);
stm->filter = fz_keepfilter(flt);
return stm;
}
fz_stream *
fz_openbuffer(fz_buffer *buf)
{
fz_stream *stm;
stm = fz_newstream(FZ_SBUFFER);
stm->buffer = fz_keepbuffer(buf);
stm->buffer->eof = 1;
return stm;
}
fz_stream *
fz_openmemory(unsigned char *mem, int len)
{
fz_buffer *buf;
fz_stream *stm;
buf = fz_newbufferwithmemory(mem, len);
stm = fz_openbuffer(buf);
fz_dropbuffer(buf);
return stm;
}
|