-
Notifications
You must be signed in to change notification settings - Fork 3
/
buffer.h
26 lines (21 loc) · 647 Bytes
/
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
#ifndef BUFFER_H
#define BUFFER_H
/**
* String Buffer.
*/
#include <stdlib.h>
#include <string.h>
struct buffer {
char *pos; /* start position of string */
char *last; /* end position of string */
char *start; /* start of buffer */
char *end; /* end of buffer */
};
#define buffer_size(buf) (buf->last - buf->pos)
#define buffer_available(buf) (buf->end - buf->last)
#define buffer_capacity(buf) (buf->end - buf->start)
struct buffer *buffer_create(size_t size);
void buffer_shrink(struct buffer *buf);
int buffer_grow(struct buffer *buf, size_t extra);
void buffer_delete(struct buffer *buf);
#endif