buffer.h revision bbe0ee356dc610a8d054b336534d8f33c49a36b7
#ifndef __BUFFER_H
#define __BUFFER_H
struct buffer {
const void *data;
};
/* 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 static sized buffer. Writes past this size will kill the program. */
/* Create a modifyable buffer from given data. */
/* Create a non-modifyable buffer from given data. */
/* 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. */
/* 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-modifyable. WARNING: The returned address may become invalid
if you add more data to buffer. */
/* 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 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 *
{
if (used_size_r != NULL)
}
/* Returns the current used buffer size. */
{
}
#endif