forked from uber-archive/statsrelay
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuffer.h
61 lines (44 loc) · 1.52 KB
/
buffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef BUFFER_H
#define BUFFER_H
#include <sys/types.h>
struct buffer {
char *ptr;
char *head;
char *tail;
size_t size;
};
typedef struct buffer buffer_t;
// Init a buffer to default size
int buffer_init(buffer_t *);
int buffer_init_contents(buffer_t *, const char *, size_t);
// Create a new buffer at specified size
buffer_t *create_buffer(size_t size);
// Returns the size of the consumed space in buffer
size_t buffer_datacount(buffer_t *);
// Returns the size of available space in buffer
size_t buffer_spacecount(buffer_t *);
// Returns a pointer to the beginning of used space
char *buffer_head(buffer_t *);
// Returns a pointer to the end of used space
char *buffer_tail(buffer_t *);
// Doubles the size of the buffer
int buffer_expand(buffer_t *);
// Expands the buffer to the given size
int buffer_newsize(buffer_t *b, size_t newsize);
// Advances head
int buffer_consume(buffer_t *, size_t);
// Advances tail
int buffer_produced(buffer_t *, size_t);
// Sets to the new contents, expanding if necessary
int buffer_set(buffer_t *, const char *data, size_t size);
// Copy data from head to the beginning of the buffer
int buffer_realign(buffer_t *);
// Frees all memory associated with the buffer
void buffer_destroy(buffer_t *);
// Delete the buffer object
void delete_buffer(buffer_t *);
/* Take this piece of memory and wrap it. Don't copy it, don't touch it,
just wrap it. This is entirely for interface compatibilty with things
that take buffers */
void buffer_wrap(buffer_t *, const char *, size_t);
#endif