-
Notifications
You must be signed in to change notification settings - Fork 1
/
buffer.h
48 lines (40 loc) · 1.5 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
/*
* Generic dynamically-allocated auto-growing in-memory buffers.
*
* Written by Solar Designer <solar at openwall.com> in 2006,
* revised by ABC <abc at openwall.com> in 2014 (buffer_appenduc() function).
* No copyright is claimed, and the software is hereby placed in the public
* domain. In case this attempt to disclaim copyright and place the software
* in the public domain is deemed null and void, then the software is
* Copyright (c) 2006 Solar Designer <solar at openwall.com>
* Copyright (c) 2014 ABC <abc at openwall.com>
* and it is hereby released to the general public under the following terms:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted.
*
* There's ABSOLUTELY NO WARRANTY, express or implied.
*/
#ifndef _BLISTS_BUFFER_H
#define _BLISTS_BUFFER_H
#include <sys/types.h>
#define BUFFER_GROW_STEP 0x8000
#define BUFFER_GROW_MAX 0x1000000
struct buffer {
char *start, *end, *ptr;
int error;
};
extern int buffer_init(struct buffer *buf, size_t size);
extern void buffer_free(struct buffer *buf);
extern int buffer_append(struct buffer *buf, const char *what, size_t length);
extern int buffer_appendc(struct buffer *buf, char what);
extern void buffer_appenduc(struct buffer *buf, unsigned int what);
extern int buffer_appendf(struct buffer *buf, const char *fmt, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 3)));
#else
;
#endif
#define buffer_appends(buf, what) \
buffer_append((buf), (what), strlen(what))
#endif