Import ezmlm 0.53
[ezmlm] / substdio_in.3
CommitLineData
5b62e993
MW
1.TH substdio_in 3
2.SH NAME
3substdio_in \- substdio input routines
4.SH SYNTAX
5.B #include <substdio.h>
6
7int \fBsubstdio_get\fP(&\fIs\fR,\fIto\fR,\fIlen\fR);
8
9int \fBsubstdio_bget\fP(&\fIs\fR,\fIto\fR,\fIlen\fR);
10
11int \fBsubstdio_feed\fP(&\fIs\fR);
12
13char *\fBsubstdio_peek\fP(&\fIs\fR);
14
15void \fBsubstdio_seek\fP(&\fIs\fR,\fIlen\fR);
16
17substdio \fIs\fR;
18.br
19char *\fIto\fR;
20.br
21int \fIlen\fR;
22.SH DESCRIPTION
23.B substdio_get
24reads at most
25.I len
26characters from
27.I s
28into the character array
29.IR to .
30It returns the number of characters read,
310 for end of file,
32or -1 for error,
33setting
34.B errno
35appropriately.
36
37.B substdio_bget
38has the same function as
39.BR substdio_get .
40The difference is what happens when there is no buffered data and
41.I len
42exceeds the buffer size:
43.B substdio_get
44tries to read
45.I len
46characters, whereas
47.B substdio_bget
48tries to read one buffer of characters.
49In some cases
50.B substdio_bget
51will be more efficient than
52.BR substdio_get .
53
54.B substdio_feed
55makes sure that there is buffered data,
56so that the next
57.B substdio_get
58or
59.B substdio_bget
60will succeed.
61If the buffer is empty,
62.B substdio_feed
63tries to fill it;
64it returns 0 for end of file, -1 for error,
65or the number of buffered characters on success.
66If the buffer already had data,
67.B substdio_feed
68leaves it alone and returns the number of buffered characters.
69
70.B substdio_peek
71returns a pointer to the buffered data.
72
73.B substdio_seek
74throws away
75.I len
76buffered characters,
77as if they had been read.
78.I len
79must be at least 0 and at most the amount of buffered data.
80
81The
82.B substdio_PEEK
83and
84.B substdio_SEEK
85macros behave the same way as
86.B substdio_peek
87and
88.B substdio_seek
89but may evaluate their arguments several times.
90
91The point of
92.B substdio_peek
93and
94.B substdio_seek
95is to read data without unnecessary copies.
96Sample code:
97
98.EX
99 for (;;) {
100.br
101 n = substdio_feed(s);
102.br
103 if (n <= 0) return n;
104.br
105 x = substdio_PEEK(s);
106.br
107 handle(x,n);
108.br
109 substdio_SEEK(s,n);
110.br
111 }
112.EE
113
114The
115.B SUBSTDIO_INSIZE
116macro is defined as a reasonably large input buffer size for
117.BR substdio_fdbuf .
118.SH "INTERNALS"
119When a
120.B substdio
121variable
122.I s
123is used for input,
124there is free buffer space from
125.I s\fB.x
126to
127.I s\fB.x\fR +
128.I s\fB.n\fR;
129data is buffered from
130.I s\fB.x\fR +
131.I s\fB.n
132to
133.I s\fB.x\fR +
134.I s\fB.n\fR +
135.I s\fB.p\fR;
136the total buffer length is
137.I s\fB.n\fR +
138.I s\fB.p\fR.
139.SH "SEE ALSO"
140substdio(3)