debian/rules: Use `git' potty wrapper.
[qmail] / stralloc.3
CommitLineData
2117e02e
MW
1.TH stralloc 3
2.SH NAME
3stralloc \- dynamically allocated strings
4.SH SYNTAX
5.B #include <stralloc.h>
6
7int \fBstralloc_ready\fP(&\fIsa\fR,\fIlen\fR);
8.br
9int \fBstralloc_readyplus\fP(&\fIsa\fR,\fIlen\fR);
10
11int \fBstralloc_copy\fP(&\fIsa\fR,&\fIsa2\fR);
12.br
13int \fBstralloc_copys\fP(&\fIsa\fR,\fIbuf\fR);
14.br
15int \fBstralloc_copyb\fP(&\fIsa\fR,\fIbuf\fR,\fIlen\fR);
16
17int \fBstralloc_cat\fP(&\fIsa\fR,&\fIsa2\fR);
18.br
19int \fBstralloc_cats\fP(&\fIsa\fR,\fIbuf\fR);
20.br
21int \fBstralloc_catb\fP(&\fIsa\fR,\fIbuf\fR,\fIlen\fR);
22
23int \fBstralloc_append\fP(&\fIsa\fR,\fIbuf\fR);
24.br
25int \fBstralloc_0\fP(&\fIsa\fR);
26
27int \fBstralloc_starts\fP(&\fIsa\fR,\fIbuf\fR);
28
29stralloc \fIsa\fR = {0};
30.br
31stralloc \fIsa2\fR = {0};
32.br
33unsigned int \fIlen\fR;
34.br
35char *\fIbuf\fR;
36.SH DESCRIPTION
37A
38.B stralloc
39variable holds a string in dynamically allocated space.
40String length is limited only by memory.
41String contents are unrestricted.
42
43The
44.B stralloc
45structure has three components:
46.I sa\fB.s
47is a pointer to the string, or 0 if it is not allocated;
48.I sa\fB.len
49is the number of bytes in the string, if it is allocated;
50.I sa\fB.a
51is the number of bytes allocated for the string, if it is allocated.
52A
53.B stralloc
54variable should be initialized to {0},
55meaning unallocated.
56
57.B stralloc_ready
58makes sure that
59.I sa
60has enough space allocated for
61.I len
62characters.
63It allocates extra space if necessary.
64
65.B stralloc_readyplus
66makes sure that
67.I sa
68has enough space allocated for
69.I len
70characters more than its current length.
71If
72.I sa
73is unallocated,
74.B stralloc_readyplus
75is the same as
76.BR stralloc_ready .
77
78.B stralloc_copy
79copies
80.I sa2
81to
82.IR sa ,
83allocating space if necessary.
84Here
85.I sa2
86is an allocated
87.B stralloc
88variable.
89
90.B stralloc_copys
91copies a 0-terminated string,
92.IR buf ,
93to
94.IR sa ,
95without the 0.
96
97.B stralloc_copyb
98copies
99.I len
100characters from
101.I buf
102to
103.IR sa .
104
105.B stralloc_cat
106appends
107.I sa2
108to
109.IR sa ,
110allocating space if necessary.
111If
112.I sa
113is unallocated,
114.B stralloc_cat
115is the same as
116.BR stralloc_copy .
117
118.B stralloc_cats
119and
120.B stralloc_catb
121are analogous to
122.B stralloc_copys
123and
124.BR stralloc_copyb .
125
126.B stralloc_append
127adds a single character,
128.IR *buf ,
129to
130.IR sa ,
131allocating space if necessary.
132
133.B stralloc_0
134adds a single 0 character
135to
136.IR sa .
137
138.B stralloc_starts
139returns 1 if the 0-terminated string
140.IR buf ,
141without the 0,
142is a prefix of
143.IR sa .
144.SH "ERROR HANDLING"
145If a
146.B stralloc
147routine runs out of memory,
148it leaves
149.I sa
150alone and returns 0,
151setting
152.B errno
153appropriately.
154On success it returns 1;
155this guarantees that
156.I sa
157is allocated.
158.SH "SEE ALSO"
159alloc(3),
160error(3)