Wed, 10 Oct 2012 10:04:01 +0200
added flag field to buffer
1 #ifndef BUFFER_H
2 #define BUFFER_H
4 #include <stdio.h>
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
10 #define UCX_BUFFER_DEFAULT 0x00
11 #define UCX_BUFFER_AUTOFREE 0x01
13 /* the user shall not modify values */
14 typedef struct UcxBuffer UcxBuffer;
16 /* if space is NULL, new space is allocated and the autofree flag is enforced */
17 UcxBuffer *ucx_buffer_new(void *space, size_t length, int flags);
18 void ucx_buffer_free(UcxBuffer* buffer);
20 /*
21 * Moves the position of the buffer to a new position relative to whence.
22 *
23 * SEEK_SET marks the start of the buffer
24 * SEEK_CUR marks the current position
25 * SEEK_END marks the first 0-byte in the buffer
26 *
27 * ucx_memseek returns 0 on success and -1 if the new position is beyond the
28 * bounds of the allocated buffer. In that case the position of the buffer
29 * remains unchanged.
30 *
31 */
32 int ucx_buffer_seek(UcxBuffer *buffer, off_t offset, int whence);
33 size_t ucx_buffer_tell(UcxBuffer *buffer);
35 /*
36 * returns non-zero, iff the current buffer position has exceeded the last
37 * available byte of the underlying buffer
38 *
39 */
40 int ucx_buffer_eof(UcxBuffer *buffer);
42 size_t ucx_bufio(void *d, size_t s, size_t n, UcxBuffer* b, _Bool read);
43 #define ucx_buffer_write(data, itemsize, nitems, buffer) \
44 ucx_bufio(data, itemsize, nitems, buffer, 0)
45 #define ucx_buffer_read(data, itemsize, nitems, buffer) \
46 ucx_bufio(data, itemsize, nitems, buffer, 1)
47 int ucx_buffer_putc(UcxBuffer *b, int c);
48 int ucx_buffer_getc(UcxBuffer *b);
50 #ifdef __cplusplus
51 }
52 #endif
54 #endif /* BUFFER_H */