diff -r c80c910fe191 -r abae4669fba7 ucx/buffer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ucx/buffer.h Wed Oct 10 09:54:57 2012 +0200 @@ -0,0 +1,52 @@ +#ifndef BUFFER_H +#define BUFFER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* the user shall not modify values */ +typedef struct UcxBuffer UcxBuffer; + +UcxBuffer *ucx_buffer_new(void *space, size_t length); +void ucx_buffer_free(UcxBuffer* buffer); + +/* + * Moves the position of the buffer to a new position relative to whence. + * + * SEEK_SET marks the start of the buffer + * SEEK_CUR marks the current position + * SEEK_END marks the first 0-byte in the buffer + * + * ucx_memseek returns 0 on success and -1 if the new position is beyond the + * bounds of the allocated buffer. In that case the position of the buffer + * remains unchanged. + * + */ +int ucx_buffer_seek(UcxBuffer *buffer, off_t offset, int whence); +size_t ucx_buffer_tell(UcxBuffer *buffer); + +/* + * returns non-zero, iff the current buffer position has exceeded the last + * available byte of the underlying buffer + * + */ +int ucx_buffer_eof(UcxBuffer *buffer); + +size_t ucx_bufio(void *d, size_t s, size_t n, UcxBuffer* b, _Bool read); +#define ucx_buffer_write(data, itemsize, nitems, buffer) \ + ucx_bufio(data, itemsize, nitems, buffer, 0) +#define ucx_buffer_read(data, itemsize, nitems, buffer) \ + ucx_bufio(data, itemsize, nitems, buffer, 1) +int ucx_buffer_putc(UcxBuffer *b, int c); +int ucx_buffer_getc(UcxBuffer *b); + +#ifdef __cplusplus +} +#endif + +#endif /* BUFFER_H */ +