0
|
1 .\" |
|
2 .\" buf_sub.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_SUB 3 |
|
20 .Os |
|
21 .\" NAME |
|
22 .Sh NAME |
|
23 .Nm buf_sub |
|
24 .Nd duplicate a specific portion from the buffer |
|
25 .\" SYNOPSIS |
|
26 .Sh SYNOPSIS |
|
27 .In buf.h |
|
28 .Ft bool |
|
29 .Fn buf_sub "struct buf *b" "const struct buf *src" "size_t pos" "size_t count" |
|
30 .\" DESCRIPTION |
|
31 .Sh DESCRIPTION |
|
32 Extract the portion at position |
|
33 .Fa pos |
|
34 from the buffer specified by |
|
35 .Fa src |
|
36 with |
|
37 .Fa count |
|
38 number of characters and set to |
|
39 .Fa b . |
|
40 .Pp |
|
41 This function will first initialize and allocate the buffer specified by |
|
42 .Fa b |
|
43 to fill the portion length. |
|
44 It should not contain any data because it will be overwritten. |
|
45 .Pp |
|
46 The |
|
47 .Fa count |
|
48 argument can be set to -1 to extract data until the end of the |
|
49 .Fa src |
|
50 buffer. |
|
51 .Pp |
|
52 Undefined behavior may occur if the |
|
53 .Fa pos |
|
54 argument is outside of the buffer bounds. |
|
55 .\" RETURN VALUE |
|
56 .Sh RETURN VALUE |
|
57 The |
|
58 .Fn buf_sub |
|
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 Memory allocation failed. |
|
67 .El |
|
68 .\" SEE ALSO |
|
69 .Sh SEE ALSO |
|
70 .Xr libbuf 3 |
|
71 .\" AUTHORS |
|
72 .Sh AUTHORS |
|
73 The |
|
74 .Nm libbuf |
|
75 library was written by |
|
76 .An David Demelier <markand@malikania.fr> |