1 /* A simple growing buffer for GDB.
3 Copyright (C) 2009-2015 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #include "common-defs.h"
21 #include "xml-utils.h"
25 buffer_grow (struct buffer
*buffer
, const char *data
, size_t size
)
28 size_t new_buffer_size
;
33 new_buffer_size
= buffer
->buffer_size
;
35 if (new_buffer_size
== 0)
38 while (buffer
->used_size
+ size
> new_buffer_size
)
40 new_buffer
= xrealloc (buffer
->buffer
, new_buffer_size
);
41 memcpy (new_buffer
+ buffer
->used_size
, data
, size
);
42 buffer
->buffer
= new_buffer
;
43 buffer
->buffer_size
= new_buffer_size
;
44 buffer
->used_size
+= size
;
48 buffer_free (struct buffer
*buffer
)
53 xfree (buffer
->buffer
);
54 buffer
->buffer
= NULL
;
55 buffer
->buffer_size
= 0;
56 buffer
->used_size
= 0;
60 buffer_init (struct buffer
*buffer
)
62 memset (buffer
, 0, sizeof (*buffer
));
66 buffer_finish (struct buffer
*buffer
)
68 char *ret
= buffer
->buffer
;
69 buffer
->buffer
= NULL
;
70 buffer
->buffer_size
= 0;
71 buffer
->used_size
= 0;
76 buffer_xml_printf (struct buffer
*buffer
, const char *format
, ...)
83 va_start (ap
, format
);
86 for (f
= format
; *f
; f
++)
93 const char *f_old
= f
;
98 str
= va_arg (ap
, char *);
101 sprintf (str
, "%d", va_arg (ap
, int));
104 sprintf (str
, "%u", va_arg (ap
, unsigned int));
107 sprintf (str
, "%x", va_arg (ap
, unsigned int));
110 sprintf (str
, "%o", va_arg (ap
, unsigned int));
117 sprintf (str
, "%ld", va_arg (ap
, long));
120 sprintf (str
, "%lu", va_arg (ap
, unsigned long));
123 sprintf (str
, "%lx", va_arg (ap
, unsigned long));
126 sprintf (str
, "%lo", va_arg (ap
, unsigned long));
133 sprintf (str
, "%" PRId64
,
134 (int64_t) va_arg (ap
, long long));
137 sprintf (str
, "%" PRIu64
,
138 (uint64_t) va_arg (ap
, unsigned long long));
141 sprintf (str
, "%" PRIx64
,
142 (uint64_t) va_arg (ap
, unsigned long long));
145 sprintf (str
, "%" PRIo64
,
146 (uint64_t) va_arg (ap
, unsigned long long));
165 buffer_grow (buffer
, prev
, f_old
- prev
- 1);
166 p
= xml_escape_text (str
);
167 buffer_grow_str (buffer
, p
);
177 buffer_grow_str (buffer
, prev
);
This page took 0.033013 seconds and 4 git commands to generate.