1 /* $Id: buffer.h 6295 2003-04-16 05:46:38Z rra $
3 ** Counted, reusable memory buffer.
5 ** A buffer is an allocated bit of memory with a known size and a separate
6 ** data length. It's intended to store strings and can be reused repeatedly
7 ** to minimize the number of memory allocations. Buffers increase in
10 ** A buffer contains a notion of the data that's been used and the data
11 ** that's been left, used when the buffer is an I/O buffer where lots of data
12 ** is buffered and then slowly processed out of the buffer. The total length
13 ** of the data is used + left. If a buffer is just used to store some data,
14 ** used can be set to 0 and left stores the length of the data.
18 #define INN_BUFFER_H 1
20 #include <inn/defines.h>
23 size_t size; /* Total allocated length. */
24 size_t used; /* Data already used. */
25 size_t left; /* Remaining unused data. */
26 char *data; /* Pointer to allocated memory. */
31 /* Allocate a new buffer and initialize its contents. */
32 struct buffer *buffer_new(void);
34 /* Resize a buffer to be at least as large as the provided size. */
35 void buffer_resize(struct buffer *, size_t);
37 /* Set the buffer contents, ignoring anything currently there. */
38 void buffer_set(struct buffer *, const char *data, size_t length);
40 /* Append data to the buffer. */
41 void buffer_append(struct buffer *, const char *data, size_t length);
43 /* Swap the contents of two buffers. */
44 void buffer_swap(struct buffer *, struct buffer *);
48 #endif /* INN_BUFFER_H */