Use gbuf in server.c
[cmus.git] / gbuf.h
bloba0d2dc1093d16bb75f9fcb8e45b8a3c9f1dab650
1 #ifndef GBUF_H
2 #define GBUF_H
4 #include "debug.h"
6 struct gbuf {
7 char *buffer;
8 size_t alloc;
9 size_t len;
12 extern char gbuf_empty_buffer[];
14 #define GBUF(name) struct gbuf name = { gbuf_empty_buffer, 0, 0 }
16 static inline void gbuf_clear(struct gbuf *buf)
18 buf->len = 0;
19 buf->buffer[0] = 0;
22 static inline size_t gbuf_avail(struct gbuf *buf)
24 if (buf->alloc)
25 return buf->alloc - buf->len - 1;
26 return 0;
29 void gbuf_grow(struct gbuf *buf, size_t more);
30 void gbuf_free(struct gbuf *buf);
31 void gbuf_add_ch(struct gbuf *buf, char ch);
32 void gbuf_add_bytes(struct gbuf *buf, const void *data, size_t len);
33 void gbuf_add_str(struct gbuf *buf, const char *str);
34 void gbuf_addf(struct gbuf *buf, const char *fmt, ...) __FORMAT(2, 3);
35 void gbuf_set(struct gbuf *buf, int c, size_t count);
36 char *gbuf_steal(struct gbuf *buf);
38 #endif