ucx/buffer.h

changeset 60
abae4669fba7
parent 58
733f22fca61a
child 61
fb07a0ab9a17
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ucx/buffer.h	Wed Oct 10 09:54:57 2012 +0200
     1.3 @@ -0,0 +1,52 @@
     1.4 +#ifndef BUFFER_H
     1.5 +#define	BUFFER_H
     1.6 +
     1.7 +#include <stdio.h>
     1.8 +
     1.9 +#ifdef	__cplusplus
    1.10 +extern "C" {
    1.11 +#endif
    1.12 +
    1.13 +
    1.14 +/* the user shall not modify values */
    1.15 +typedef struct UcxBuffer UcxBuffer;
    1.16 +
    1.17 +UcxBuffer *ucx_buffer_new(void *space, size_t length);
    1.18 +void ucx_buffer_free(UcxBuffer* buffer);
    1.19 +
    1.20 +/*
    1.21 + * Moves the position of the buffer to a new position relative to whence.
    1.22 + *
    1.23 + * SEEK_SET marks the start of the buffer
    1.24 + * SEEK_CUR marks the current position
    1.25 + * SEEK_END marks the first 0-byte in the buffer
    1.26 + *
    1.27 + * ucx_memseek returns 0 on success and -1 if the new position is beyond the
    1.28 + * bounds of the allocated buffer. In that case the position of the buffer
    1.29 + * remains unchanged.
    1.30 + *
    1.31 + */
    1.32 +int ucx_buffer_seek(UcxBuffer *buffer, off_t offset, int whence);
    1.33 +size_t ucx_buffer_tell(UcxBuffer *buffer);
    1.34 +
    1.35 +/*
    1.36 + * returns non-zero, iff the current buffer position has exceeded the last
    1.37 + * available byte of the underlying buffer
    1.38 + *
    1.39 + */
    1.40 +int ucx_buffer_eof(UcxBuffer *buffer);
    1.41 +
    1.42 +size_t ucx_bufio(void *d, size_t s, size_t n, UcxBuffer* b, _Bool read);
    1.43 +#define ucx_buffer_write(data, itemsize, nitems, buffer) \
    1.44 +    ucx_bufio(data, itemsize, nitems, buffer, 0)
    1.45 +#define ucx_buffer_read(data, itemsize, nitems, buffer) \
    1.46 +        ucx_bufio(data, itemsize, nitems, buffer, 1)
    1.47 +int ucx_buffer_putc(UcxBuffer *b, int c);
    1.48 +int ucx_buffer_getc(UcxBuffer *b);
    1.49 +
    1.50 +#ifdef	__cplusplus
    1.51 +}
    1.52 +#endif
    1.53 +
    1.54 +#endif	/* BUFFER_H */
    1.55 +

mercurial