buffer.h revision e915ba86f157549b7d127f92312bc487b249df7e
#ifndef BUFFER_H
#define BUFFER_H
struct buffer {
const void *data;
void *priv[5];
};
/* WARNING: Be careful with functions that return pointers to data.
With dynamic buffers they are valid only as long as buffer is not
realloc()ed. You shouldn't rely on it being valid if you have modified
buffer in any way. */
/* Create a modifiable buffer from given data. Writes past this size will
i_panic(). */
/* Create a non-modifiable buffer from given data. */
#define buffer_create_from_data(b,d,s) ({ \
buffer_create_from_data((b), (d), (s)); })
#define buffer_create_from_const_data(b,d,s) ({ \
buffer_create_from_const_data((b), (d), (s)); })
#endif
/* Creates a dynamically growing buffer. Whenever write would exceed the
current size it's grown. */
/* Free the memory used by buffer. Not needed if the memory is free'd
directly from the memory pool. */
/* Free the memory used by buffer structure, but return the buffer data
unfree'd. */
/* Returns the pool buffer was created with. */
/* Reset the buffer. used size and it's contents are zeroed. */
/* Write data to buffer at specified position. */
/* Append data to buffer. */
/* Append character to buffer. */
/* Insert data to buffer. */
/* Delete data from buffer. */
/* Fill buffer with zero bytes. */
/* Copy data from buffer to another. The buffers may be same in which case
it's internal copying, possibly with overlapping positions (ie. memmove()
like functionality). copy_size may be set to (size_t)-1 to copy the rest of
the used data in buffer. */
/* Append data to buffer from another. copy_size may be set to (size_t)-1 to
copy the rest of the used data in buffer. */
/* Returns pointer to specified position in buffer. WARNING: The returned
address may become invalid if you add more data to buffer. */
/* Increase the buffer usage by given size, and return a pointer to beginning
of it. */
/* Like buffer_get_data(), but don't return it as const. Returns NULL if the
buffer is non-modifiable. WARNING: The returned address may become invalid
if you add more data to buffer. */
ATTR_NULL(2);
/* Set the "used size" of buffer, ie. 0 would set the buffer empty.
Must not be used to grow buffer. */
/* Returns the current buffer size. */
/* Returns how many bytes we can write to buffer without increasing its size.
With dynamic buffers this is buffer_get_size()-1, because the extra 1 byte
is reserved for str_c()'s NUL. */
/* Returns TRUE if buffer contents are identical. */
/* Returns pointer to beginning of buffer data. Current used size of buffer is
stored in used_size if it's non-NULL. */
static inline const void * ATTR_NULL(2)
{
if (used_size_r != NULL)
}
/* Returns the current used buffer size. */
{
}
/* Crash if buffer was allocated from data stack and stack frame has changed.
This can be used as an assert-like check to verify that it's valid to
increase the buffer size here, instead of crashing only randomly when the
buffer needs to be increased. */
#endif