20 #if !(defined(__GNUC__) || defined(__clang__)) && !defined(__attribute__)
21 #define __attribute__(x)
24 #define BUFFER_INISIZ (1<<12)
38 char initial[BUFFER_INISIZ];
96 #define buffer_dup(b,buf) (buffer_dupl(b,buf,NULL))
108 #define buffer_vprintf buffer_putvfstring
118 __attribute__ (( format(printf,2,3) )) ;
119 #define buffer_printf buffer_putfstring
134 #define buffer_putstring(b,s) (buffer_putlstring(b,s,strlen(s)))
141 #define buffer_putliteral(b,l) (buffer_putlstring(b,l "",sizeof(l)-1))
158 #define buffer_tostring(b) buffer_tolstring(b, NULL)
203 #define BUFFER_STACK(name,size) \
205 char name##_ubuf[size > BUFFER_INISIZ ? size : 1]; \
207 buffer_max(name, size);\
208 buffer_ubuf(name, name##_ubuf, size);
217 #define BUFFER_STACK_ABORT(name,size) \
218 BUFFER_STACK(name,size);\
219 buffer_abortonfailure(name, 1);
228 #define BUFFER_STACK_PRINT(name,size,...) \
229 BUFFER_STACK(name,size);\
230 buffer_putfstring(name, __VA_ARGS__);
int buffer_putvfstring(buffer_t *b, const char *format, va_list ap)
Print the formatted output to the buffer.
int buffer_putfstring(buffer_t *b, const char *format,...) __attribute__((format(printf
Appends the formatted output to the buffer.
int buffer_seek(buffer_t *b, size_t pos)
Seek to a position.
void buffer_rewind(buffer_t *b, size_t n)
Rewinds the buffer to position n.
void buffer_max(buffer_t *b, size_t max)
Set the maximum size of the buffer.
void buffer_init(buffer_t *b)
Initialize a buffer.
int buffer_putlstring(buffer_t *b, const char *str, size_t len)
Appends the string to the end of the buffer.
void buffer_free(buffer_t *b)
Free any resources and memory in use by a buffer.
int buffer_grow(buffer_t *b, size_t n)
Make room for at least n additional chars.
void buffer_abortonfailure(buffer_t *b, int abortonfailure)
Set the buffer to call fatal(...) on error instead of returning an error code.
const char * buffer_tolstring(buffer_t *b, size_t *size)
Returns the buffer as a string.
size_t buffer_pos(buffer_t *b)
Get the current position in the buffer.
void buffer_ubuf(buffer_t *b, char *buf, size_t len)
Use the provided buffer as a starting buffer.
int buffer_dupl(buffer_t *b, char **buf, size_t *l)
Make a heap allocated copy of the buffer.