Circbuf
0.0.1
Circular Buffer for C
Loading...
Searching...
No Matches
circbuf.h
1
#ifndef _CIRCBUF_H_
2
#define _CIRCBUF_H_
3
4
#include <stdbool.h>
/* bool */
5
#include <stddef.h>
/* size_t */
6
7
#include "
vector.h
"
8
9
typedef
vector_t
circbuf_t
;
10
11
typedef
struct
12
{
13
alloc_opts_t
alloc_opts
;
14
size_t
ext_header_size;
15
size_t
initial_cap;
/* in bytes */
16
}
17
circbuf_opts_t;
18
19
typedef
vector_status_t
circbuf_status_t
;
20
21
22
#define circbuf_create(...) \
23
circbuf_create_(&(circbuf_opts_t){ \
24
.initial_cap = 1024, \
25
__VA_ARGS__ \
26
})
27
28
29
/*
30
* Create circbuf according to opts.
31
*/
32
circbuf_t
*circbuf_create_(
const
circbuf_opts_t *
const
opts);
33
34
35
/*
36
* Makes a copy of the circbuf.
37
*/
38
circbuf_t
*circbuf_clone(
const
circbuf_t
*
const
circbuf);
39
40
41
/*
42
* Free resources of the circbuf.
43
*/
44
void
circbuf_destroy(
circbuf_t
*
const
circbuf);
45
46
47
/*
48
* Adjust circbuf capacity.
49
*/
50
circbuf_status_t
circbuf_resize(
circbuf_t
**
const
circbuf,
const
size_t
capacity);
51
52
53
/*
54
* Returns current capacity of the circbuf.
55
*/
56
size_t
circbuf_capacity(
const
circbuf_t
*
const
circbuf);
57
58
59
/*
60
* Discard contents of the circbuf.
61
*/
62
void
circbuf_clear(
circbuf_t
*
const
circbuf);
63
64
65
/*
66
* Returns amount of bytes available for read operation from circbuf.
67
*/
68
size_t
circbuf_avail_to_read(
const
circbuf_t
*
const
circbuf);
69
70
71
/*
72
* Returns amount of bytes available for write operation into circbuf.
73
*/
74
size_t
circbuf_avail_to_write(
const
circbuf_t
*
const
circbuf);
75
76
77
/*
78
* Read `size` amount of bytes from the circbuf.
79
* Returns amout of bytes read.
80
* `out` buffer has to be at least `size` long.
81
*/
82
size_t
circbuf_read(
circbuf_t
*
const
circbuf,
const
size_t
size,
void
*
const
out);
83
84
85
/*
86
* Write `size` amount of bytes into the circbuf.
87
* Returns amout of bytes wrote.
88
* `in` buffer has to be at least `size` long.
89
*/
90
size_t
circbuf_write(
circbuf_t
*
const
circbuf,
const
size_t
size,
void
*
const
in);
91
92
93
/*
94
* Discard number of bytes stored in the circbuf.
95
*/
96
size_t
circbuf_skip(
circbuf_t
*
const
circbuf,
const
size_t
size);
97
98
99
#endif
/*_CIRCBUF_H_*/
alloc_opts
#define alloc_opts(...)
alloc_opts_t
vector_t
vector.h
vector_status_t
vector_status_t
src
circbuf.h
Generated by
1.11.0