/
soldout_buffer.3
270 lines (270 loc) · 5.22 KB
/
soldout_buffer.3
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
.\"
.\" Copyright (c) 2009 - 2016 Natacha Porté <natacha@instinctive.eu>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd September 12, 2016
.Dt SOLDOUT_BUFFER 3
.Os
.Sh NAME
.Nm soldout_buffer ,
.Nm bufcasecmp ,
.Nm bufcmp ,
.Nm bufcmps ,
.Nm bufdup ,
.Nm bufgrow ,
.Nm bufnew ,
.Nm bufnullterm ,
.Nm bufprintf ,
.Nm bufput ,
.Nm bufputs ,
.Nm bufputc ,
.Nm bufrelease ,
.Nm bufreset ,
.Nm bufset ,
.Nm bufslurp ,
.Nm buftoi ,
.Nm vbufprintf
.Nd buffer handling functions for soldout
.Sh SYNOPSIS
.In buffer.h
.Pp
.Fd "#define CONST_BUF(name, string)"
.Fd "#define VOLATILE_BUF(name, strname)"
.Fd "#define BUFPUTSL(output, literal)"
.Ft int
.Fo bufcasecmp
.Fa "const struct buf *a"
.Fa "const struct buf *b"
.Fc
.Ft int
.Fo bufcmp
.Fa "const struct buf *a"
.Fa "const struct buf *b"
.Fc
.Ft int
.Fo bufcmps
.Fa "const struct buf *a"
.Fa "const char *b"
.Fc
.Ft "struct buf *"
.Fo bufdup
.Fa "const struct buf *src"
.Fa "size_t dupunit"
.Fc
.Ft int
.Fo bufgrow
.Fa "struct buf *buf"
.Fa "size_t sz"
.Fc
.Ft "struct buf *"
.Fo bufnew
.Fa "size_t unit"
.Fc
.Ft void
.Fo bufnullterm
.Fa "struct buf *buf"
.Fc
.Ft void
.Fo bufprintf
.Fa "struct buf *buf"
.Fa "const char *fmt"
.Fa ...
.Fc
.Ft void
.Fo bufput
.Fa "struct buf *buf"
.Fa "const void *data"
.Fa "size_t len"
.Fc
.Ft void
.Fo bufputs
.Fa "struct buf *buf"
.Fa "const char *str"
.Fc
.Ft void
.Fo bufputc
.Fa "struct buf *buf"
.Fa "char c"
.Fc
.Ft void
.Fo bufrelease
.Fa "struct buf *buf"
.Fc
.Ft void
.Fo bufreset
.Fa "struct buf *buf"
.Fc
.Ft void
.Fo bufset
.Fa "struct buf **dest"
.Fa "struct buf *src"
.Fc
.Ft void
.Fo bufslurp
.Fa "struct buf *buf"
.Fa "size_t len"
.Fc
.Ft int
.Fo buftoi
.Fa "struct buf *buf"
.Fa "size_t offset_i"
.Fa "size_t *offset_o"
.Fc
.Ft void
.Fo vbufprintf
.Fa "struct buf *buf"
.Fa "const char *fmt"
.Fa "va_list ap"
.Fc
.Vt extern long buffer_stat_nb;
.Vt extern size_t buffer_stat_alloc_bytes;
.Sh DESCRIPTION
.Ss Variables
Compile time options.
Statistics are kept about memory usage.
.Bl -ohang
.It Va buffer_stat_nb
show how many buffers were created.
.It Va buffer_stat_alloc_bytes
show how many bytes were allocated.
.El
.Ss Types
.Bl -ohang
.It Vt "struct buf"
character array buffer.
Has this form:
.Bd -literal -offset indent
struct buf {
char *data; /* actual character data */
size_t size; /* size of the string */
size_t asize; /* allocated size (0 = volatile buffer) */
size_t unit; /* reallocation unit size (0 = read-only buffer) */
int ref; /* reference count */
};
.Ed
.El
.Ss Macros
.Bl -ohang
.It Dv CONST_BUF
create a global buffer
.Va name
from a string literal
.Va string .
.It Dv VOLATILE_BUF
create a volatile buffer
.Va name
on the stack from a string
.Va strname .
.It Dv BUFPUTSL
optimized
.Fn bufputs
of a string literal.
.El
.Ss Functions
.Bl -ohang
.It Fn bufcasecmp
compare two buffers ignoring case.
.It Fn bufcmp
compare two buffers.
.It Fn bufcmps
compare a buffer to a string.
.It Fn bufdup
duplicate a buffer
.Va src .
.It Fn bufgrow
increase the allocated size to the size
.Va sz .
.It Fn bufnew
create a new buffer.
.It Fn bufnullterm
terminate the string array by NUL
.Pq making a C-string .
.It Fn bufprintf
print formatted output to a buffer
.Va buf .
.It Fn bufput
append raw data to a buffer
.Va buf .
.It Fn bufputs
append a NUL-terminated string
.Va str
to a buffer
.Va buf .
.It Fn bufputc
append a single char
.Va c
to a buffer
.Va buf .
.It Fn bufrelease
decrease the reference count and free the buffer
.Va buf
if needed.
.It Fn bufreset
free internal data of the buffer
.Va buf .
.It Fn bufset
safely assign a buffer to another.
.It Fn bufslurp
remove a given number of bytes from the head of the array.
.It Fn buftoi
convert the numbers at the beginning of the buffer
.Va buf
into an
.Vt int .
.It Fn vbufprintf
.Xr stdarg 3
variant of formatted printing into a buffer
.Va buf .
.El
.Sh RETURN VALUES
The
.Fn bufcasecmp ,
.Fn bufcmp
and
.Fn bufcmps
functions return an integer less than, equal to, or greater than zero if
.Va a
is found, respectively, to be less than, to match, or be greater than
.Va b .
.Pp
The
.Fn bufdup
and
.Fn bufnew
functions return a
.Vt "struct buf *"
on success; on error they return
.Dv NULL .
.Pp
The
.Fn bufgrow
function returns on success 1; on error - 0.
.Pp
The
.Fn buftoi
function return the converted value.
.Sh SEE ALSO
.Xr soldout_markdown 3 ,
.Xr stdarg 3
.Sh AUTHORS
.An -nosplit
The
.Nm soldout
library
was written by
.An Natasha Qo Kerensikova Qc Porte Aq Mt natacha@instinctive.eu .
Manual page was originally written by
.An Massimo Manghi Aq Mt mxmanghi@apache.org ,
and rewritten to mdoc format by
.An Svyatoslav Mishyn Aq Mt juef@openmailbox.org .