summaryrefslogtreecommitdiff
path: root/include/parserutils/utils/buffer.h
blob: 5f8f696b60d3972b14829933f2604b20f3ac8f6e (plain)
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
/*
 * This file is part of LibParserUtils.
 * Licensed under the MIT License,
 *                http://www.opensource.org/licenses/mit-license.php
 * Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org>
 */

#ifndef parserutils_utils_buffer_h_
#define parserutils_utils_buffer_h_

#ifdef __cplusplus
extern "C"
{
#endif

#include <parserutils/errors.h>
#include <parserutils/functypes.h>

struct parserutils_buffer
{
	uint8_t *alloc;
	uint8_t *data;
	size_t length;
	size_t allocated;
};
typedef struct parserutils_buffer parserutils_buffer;

parserutils_error parserutils_buffer_create(parserutils_buffer **buffer);
parserutils_error parserutils_buffer_destroy(parserutils_buffer *buffer);

parserutils_error parserutils_buffer_append(parserutils_buffer *buffer, 
		const uint8_t *data, size_t len);
parserutils_error parserutils_buffer_insert(parserutils_buffer *buffer, 
		size_t offset, const uint8_t *data, size_t len);
parserutils_error parserutils_buffer_discard(parserutils_buffer *buffer, 
		size_t offset, size_t len);

parserutils_error parserutils_buffer_grow(parserutils_buffer *buffer);

parserutils_error parserutils_buffer_randomise(parserutils_buffer *buffer);

#ifdef __cplusplus
}
#endif

#endif