view src/lib/buffer.h @ 1329:ae229b7acb4c HEAD

Mailbox names are now sent through imap-quoter instead of just escaping it. This means that mailbox names that would require escapes are instead sent as literals now.
author Timo Sirainen <tss@iki.fi>
date Wed, 02 Apr 2003 05:05:38 +0300
parents fd8888f6f037
children 8f56379c3917
line wrap: on
line source

#ifndef __BUFFER_H
#define __BUFFER_H

/* Create a static sized buffer. Writes past this size will simply not
   succeed. */
buffer_t *buffer_create_static(pool_t pool, size_t size);
/* Create a static sized buffer. Writes past this size will kill the program. */
buffer_t *buffer_create_static_hard(pool_t pool, size_t size);
/* Create a modifyable buffer from given data. */
buffer_t *buffer_create_data(pool_t pool, void *data, size_t size);
/* Create a non-modifyable buffer from given data. */
buffer_t *buffer_create_const_data(pool_t pool, const void *data, size_t size);
/* Creates a dynamically growing buffer. Whenever write would exceed the
   current size it's grown. */
buffer_t *buffer_create_dynamic(pool_t pool, size_t init_size, size_t max_size);
/* Free the memory used by buffer. Not needed if the memory is free'd
   directly from the memory pool. */
void buffer_free(buffer_t *buf);
/* Free the memory used by buffer structure, but return the buffer data
   unfree'd. NOTE: Current start_pos doesn't affect the returned value. */
void *buffer_free_without_data(buffer_t *buf);

/* Write data to buffer at specified position, returns number of bytes
   written. */
size_t buffer_write(buffer_t *buf, size_t pos,
		    const void *data, size_t data_size);
/* Append data to buffer, returns number of bytes written. */
size_t buffer_append(buffer_t *buf, const void *data, size_t data_size);
/* Append character to buffer, returns 1 if written, 0 if not. */
size_t buffer_append_c(buffer_t *buf, char chr);

/* Insert data to buffer, returns number of bytes inserted. */
size_t buffer_insert(buffer_t *buf, size_t pos,
		     const void *data, size_t data_size);
/* Delete data from buffer, returns number of bytes deleted. */
size_t buffer_delete(buffer_t *buf, size_t pos, size_t size);

/* 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. Returns the number of bytes actually copied. */
size_t buffer_copy(buffer_t *dest, size_t dest_pos,
		   const buffer_t *src, size_t src_pos, size_t copy_size);
/* 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. */
size_t buffer_append_buf(buffer_t *dest, const buffer_t *src,
			 size_t src_pos, size_t copy_size);

/* Returns pointer to specified position in buffer, or NULL if there's not
   enough space. */
void *buffer_get_space(buffer_t *buf, size_t pos, size_t size);
/* Increase the buffer usage by given size, and return a pointer to beginning
   of it, or NULL if there's not enough space in buffer. */
void *buffer_append_space(buffer_t *buf, size_t size);

/* Returns pointer to beginning of buffer data. Current used size of buffer is
   stored in used_size if it's non-NULL. */
const void *buffer_get_data(const buffer_t *buf, size_t *used_size);
/* Like buffer_get_data(), but don't return it as const. Returns NULL if the
   buffer is non-modifyable. */
void *buffer_get_modifyable_data(const buffer_t *buf, size_t *used_size);

/* Set the "used size" of buffer, ie. 0 would set the buffer empty.
   Must not be used to grow buffer. */
void buffer_set_used_size(buffer_t *buf, size_t used_size);
/* Returns the current used buffer size. */
size_t buffer_get_used_size(const buffer_t *buf);

/* Change the buffer start position. The buffer acts as if data was removed or
   inserted to beginning. Returns the old start position. */
size_t buffer_set_start_pos(buffer_t *buf, size_t abs_pos);
/* Returns the current start position. */
size_t buffer_get_start_pos(const buffer_t *buf);

/* Limit buffer size temporarily. All handling is treated as if this is the
   current allocated memory size, except dynamic buffer won't be grown.
   Setting the limit to (size_t)-1 removes it. Returns the old limit. */
size_t buffer_set_limit(buffer_t *buf, size_t limit);
/* Returns the current buffer limit, or (size_t)-1 if there's none. */
size_t buffer_get_limit(const buffer_t *buf);

/* Returns the current buffer size. */
size_t buffer_get_size(const buffer_t *buf);

#endif