0
|
1 .\" |
|
2 .\" buf_reserve.3 -- simple string buffer for C |
|
3 .\" |
|
4 .\" Copyright (c) 2019-2020 David Demelier <markand@malikania.fr> |
|
5 .\" |
|
6 .\" Permission to use, copy, modify, and/or distribute this software for any |
|
7 .\" purpose with or without fee is hereby granted, provided that the above |
|
8 .\" copyright notice and this permission notice appear in all copies. |
|
9 .\" |
|
10 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
11 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
12 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
13 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
14 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
15 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
16 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
17 .\" |
|
18 .Dd October 29, 2019-2020 |
|
19 .Dt BUF_RESERVE 3 |
|
20 .Os |
|
21 .\" NAME |
|
22 .Sh NAME |
|
23 .Nm buf_reserve |
|
24 .Nd allocate more storage for next operations |
|
25 .\" SYNOPSIS |
|
26 .Sh SYNOPSIS |
|
27 .In buf.h |
|
28 .Ft bool |
|
29 .Fn buf_reserve "struct buf *b" "size_t desired" |
|
30 .\" DESCRIPTION |
|
31 .Sh DESCRIPTION |
|
32 The |
|
33 .Fn buf_reserve |
|
34 function tries to increase the buffer's capacity specified by |
|
35 .Fa b |
|
36 to the amount of |
|
37 .Fa desired . |
|
38 .Pp |
|
39 Once the new capacity is increased the next calls to any operation that would |
|
40 append data to the buffer can avoid reallocating the memory. |
|
41 This can be useful if you know in advance which storage space you need. |
|
42 .Pp |
|
43 If it was unable to acquire more memory, the buffer still contains the original |
|
44 data and capacity remains unchanged. |
|
45 In any case, the buffer length's remains unchanged and only capacity is |
|
46 increased. |
|
47 .\" RETURN VALUE |
|
48 .Sh RETURN VALUE |
|
49 The |
|
50 .Fn buf_reserve |
|
51 function returns false in case of error and |
|
52 .Va errno |
|
53 is set to indicate the error. |
|
54 .\" ERRORS |
|
55 .Sh ERRORS |
|
56 .Bl -tag -width Er |
|
57 .It Bq Er ENOMEM |
|
58 Couldn't allocate more memory. |
|
59 .El |
|
60 .\" SEE ALSO |
|
61 .Sh SEE ALSO |
|
62 .Xr libbuf 3 |
|
63 .\" AUTHORS |
|
64 .Sh AUTHORS |
|
65 The |
|
66 .Nm libbuf |
|
67 library was written by |
|
68 .An David Demelier <markand@malikania.fr> |