0
|
1 .\" |
|
2 .\" buf_resize.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_RESIZE 3 |
|
20 .Os |
|
21 .\" NAME |
|
22 .Sh NAME |
|
23 .Nm buf_resize |
|
24 .Nd change string length |
|
25 .\" SYNOPSIS |
|
26 .Sh SYNOPSIS |
|
27 .In buf.h |
|
28 .Ft bool |
|
29 .Fn buf_resize "struct buf *b" "size_t size" "char c" |
|
30 .\" DESCRIPTION |
|
31 .Sh DESCRIPTION |
|
32 Change the buffer length specified by |
|
33 .Fa b |
|
34 to the new |
|
35 .Fa size |
|
36 and optionally fill new space with character |
|
37 .Fa c . |
|
38 .Pp |
|
39 This function serves two purposes, it can reduce the string length if the |
|
40 .Fa size |
|
41 argument is smaller than current |
|
42 .Fa b |
|
43 length or it can increase it and fill the new region with |
|
44 .Fa c . |
|
45 In the first case, the function never fails in the second it may need to |
|
46 reallocate data which could fail if no memory is available. |
|
47 .Pp |
|
48 Note that in constrast to |
|
49 .Fn buf_shrink |
|
50 function, the |
|
51 .Fn buf_resize |
|
52 function never reallocate data if the new size is smaller, you may want to call |
|
53 .Fn buf_shrink |
|
54 if memory should be released. |
|
55 .\" RETURN VALUE |
|
56 .Sh RETURN VALUE |
|
57 The |
|
58 .Fn buf_resize |
|
59 function returns false in case of error and |
|
60 .Va errno |
|
61 is set to indicate the error. |
|
62 .\" ERRORS |
|
63 .Sh ERRORS |
|
64 .Bl -tag -width Er |
|
65 .It Bq Er ENOMEM |
|
66 Couldn't allocate more memory. |
|
67 .El |
|
68 .\" SEE ALSO |
|
69 .Sh SEE ALSO |
|
70 .Xr libbuf 3 , |
|
71 .Xr buf_resize 3 , |
|
72 .Xr buf_shrink 3 |
|
73 .\" AUTHORS |
|
74 .Sh AUTHORS |
|
75 The |
|
76 .Nm libbuf |
|
77 library was written by |
|
78 .An David Demelier <markand@malikania.fr> |