GDB (API)
|
00001 /* A simple growing buffer for GDB. 00002 00003 Copyright (C) 2009-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #ifndef BUFFER_H 00021 #define BUFFER_H 00022 00023 #include <stddef.h> 00024 #include <string.h> 00025 #include "ansidecl.h" 00026 00027 struct buffer 00028 { 00029 char *buffer; 00030 size_t buffer_size; /* allocated size */ 00031 size_t used_size; /* actually used size */ 00032 }; 00033 00034 /* Append DATA of size SIZE to the end of BUFFER. Grows the buffer to 00035 accommodate the new data. */ 00036 void buffer_grow (struct buffer *buffer, const char *data, size_t size); 00037 00038 /* Release any memory held by BUFFER. */ 00039 void buffer_free (struct buffer *buffer); 00040 00041 /* Initialize BUFFER. BUFFER holds no memory afterwards. */ 00042 void buffer_init (struct buffer *buffer); 00043 00044 /* Return a pointer into BUFFER data, effectivelly transfering 00045 ownership of the buffer memory to the caller. Calling buffer_free 00046 afterwards has no effect on the returned data. */ 00047 char* buffer_finish (struct buffer *buffer); 00048 00049 /* Simple printf to buffer function. Current implemented formatters: 00050 %s - grow an xml escaped text in BUFFER. 00051 %d - grow an signed integer in BUFFER. 00052 %u - grow an unsigned integer in BUFFER. 00053 %x - grow an unsigned integer formatted in hexadecimal in BUFFER. 00054 %o - grow an unsigned integer formatted in octal in BUFFER. */ 00055 void buffer_xml_printf (struct buffer *buffer, const char *format, ...) 00056 ATTRIBUTE_PRINTF (2, 3); 00057 00058 #define buffer_grow_str(BUFFER,STRING) \ 00059 buffer_grow (BUFFER, STRING, strlen (STRING)) 00060 #define buffer_grow_str0(BUFFER,STRING) \ 00061 buffer_grow (BUFFER, STRING, strlen (STRING) + 1) 00062 00063 #endif