Commit | Line | Data |
---|---|---|
d26e3629 KY |
1 | /* A simple growing buffer for GDB. |
2 | ||
32d0add0 | 3 | Copyright (C) 2009-2015 Free Software Foundation, Inc. |
d26e3629 KY |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #ifndef BUFFER_H | |
21 | #define BUFFER_H | |
22 | ||
d26e3629 KY |
23 | struct buffer |
24 | { | |
25 | char *buffer; | |
26 | size_t buffer_size; /* allocated size */ | |
27 | size_t used_size; /* actually used size */ | |
28 | }; | |
29 | ||
30 | /* Append DATA of size SIZE to the end of BUFFER. Grows the buffer to | |
31 | accommodate the new data. */ | |
32 | void buffer_grow (struct buffer *buffer, const char *data, size_t size); | |
33 | ||
34 | /* Release any memory held by BUFFER. */ | |
35 | void buffer_free (struct buffer *buffer); | |
36 | ||
37 | /* Initialize BUFFER. BUFFER holds no memory afterwards. */ | |
38 | void buffer_init (struct buffer *buffer); | |
39 | ||
40 | /* Return a pointer into BUFFER data, effectivelly transfering | |
41 | ownership of the buffer memory to the caller. Calling buffer_free | |
42 | afterwards has no effect on the returned data. */ | |
43 | char* buffer_finish (struct buffer *buffer); | |
44 | ||
45 | /* Simple printf to buffer function. Current implemented formatters: | |
46 | %s - grow an xml escaped text in BUFFER. | |
47 | %d - grow an signed integer in BUFFER. | |
48 | %u - grow an unsigned integer in BUFFER. | |
49 | %x - grow an unsigned integer formatted in hexadecimal in BUFFER. | |
50 | %o - grow an unsigned integer formatted in octal in BUFFER. */ | |
51 | void buffer_xml_printf (struct buffer *buffer, const char *format, ...) | |
52 | ATTRIBUTE_PRINTF (2, 3); | |
53 | ||
54 | #define buffer_grow_str(BUFFER,STRING) \ | |
55 | buffer_grow (BUFFER, STRING, strlen (STRING)) | |
56 | #define buffer_grow_str0(BUFFER,STRING) \ | |
57 | buffer_grow (BUFFER, STRING, strlen (STRING) + 1) | |
58 | ||
59 | #endif |