ucx/buffer.h

changeset 60
abae4669fba7
parent 58
733f22fca61a
child 61
fb07a0ab9a17
equal deleted inserted replaced
59:c80c910fe191 60:abae4669fba7
1 #ifndef BUFFER_H
2 #define BUFFER_H
3
4 #include <stdio.h>
5
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9
10
11 /* the user shall not modify values */
12 typedef struct UcxBuffer UcxBuffer;
13
14 UcxBuffer *ucx_buffer_new(void *space, size_t length);
15 void ucx_buffer_free(UcxBuffer* buffer);
16
17 /*
18 * Moves the position of the buffer to a new position relative to whence.
19 *
20 * SEEK_SET marks the start of the buffer
21 * SEEK_CUR marks the current position
22 * SEEK_END marks the first 0-byte in the buffer
23 *
24 * ucx_memseek returns 0 on success and -1 if the new position is beyond the
25 * bounds of the allocated buffer. In that case the position of the buffer
26 * remains unchanged.
27 *
28 */
29 int ucx_buffer_seek(UcxBuffer *buffer, off_t offset, int whence);
30 size_t ucx_buffer_tell(UcxBuffer *buffer);
31
32 /*
33 * returns non-zero, iff the current buffer position has exceeded the last
34 * available byte of the underlying buffer
35 *
36 */
37 int ucx_buffer_eof(UcxBuffer *buffer);
38
39 size_t ucx_bufio(void *d, size_t s, size_t n, UcxBuffer* b, _Bool read);
40 #define ucx_buffer_write(data, itemsize, nitems, buffer) \
41 ucx_bufio(data, itemsize, nitems, buffer, 0)
42 #define ucx_buffer_read(data, itemsize, nitems, buffer) \
43 ucx_bufio(data, itemsize, nitems, buffer, 1)
44 int ucx_buffer_putc(UcxBuffer *b, int c);
45 int ucx_buffer_getc(UcxBuffer *b);
46
47 #ifdef __cplusplus
48 }
49 #endif
50
51 #endif /* BUFFER_H */
52

mercurial