-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuf.h
More file actions
45 lines (39 loc) · 1.33 KB
/
buf.h
File metadata and controls
45 lines (39 loc) · 1.33 KB
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
#ifndef __buf_H_
#define __buf_H_
#include <stddef.h>
#ifndef EXTERN
#ifdef __cplusplus
#define EXTERN extern "C"
#else
#define EXTERN
#endif
#endif //EXTERN
#ifndef EXTERN
#ifdef __cplusplus
#define EXTERN extern "C"
#else
#define EXTERN
#endif
#endif //EXTERN
struct buf_t {
int error;
size_t cap;
size_t len;
char data[0];
};
EXTERN struct buf_t* buf_new(size_t size);
EXTERN void buf_del(struct buf_t* buf);
EXTERN struct buf_t* buf_append(struct buf_t* buf, void* data, size_t len);
EXTERN struct buf_t* buf_append_string(struct buf_t* buf, char* s, char* end);
EXTERN struct buf_t* buf_append_char(struct buf_t* buf, char val);
EXTERN struct buf_t* buf_append_wchar(struct buf_t* buf, wchar_t val);
EXTERN struct buf_t* buf_append_int32(struct buf_t* buf, int val);
EXTERN struct buf_t* buf_append_uint32(struct buf_t* buf, unsigned int val);
EXTERN struct buf_t* buf_append_int16(struct buf_t* buf, short val);
EXTERN struct buf_t* buf_append_uint16(struct buf_t* buf, unsigned short val);
EXTERN struct buf_t* buf_append_int8(struct buf_t* buf, char val);
EXTERN struct buf_t* buf_append_uint8(struct buf_t* buf, unsigned char val);
#define buf_ok(buf) (!((buf)->error))
#define buf_clrerr(buf) (((buf)->error = 0), (buf))
#define buf_reset(buf) (((buf)->error = 0), ((buf)->len = 0), ((buf)->data[0] = 0), (buf))
#endif //__buf_H_