libsignal-protocol-c
master
vpool.h
1
/*
2
* Copyright (c) 2006, 2008 Alexey Vatchenko <av@bsdua.org>
3
*
4
* Permission to use, copy, modify, and/or distribute this software for any
5
* purpose with or without fee is hereby granted, provided that the above
6
* copyright notice and this permission notice appear in all copies.
7
*
8
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
*/
16
17
/*
18
* VPool: implementation of pool of data with a variable size.
19
*/
20
#ifndef _VPOOL_H_
21
#define _VPOOL_H_
22
23
#include <sys/types.h>
24
#include <limits.h>
25
26
struct
vpool
{
27
void
*v_basebuf;
/* pointer returned by (re|m)alloc() */
28
void
*v_buf;
/* actual data starts here */
29
size_t
v_off;
30
size_t
v_size;
31
32
size_t
v_blksize;
33
size_t
v_limit;
34
int
v_lasterr;
35
};
36
37
enum
vpool_trunc {VPOOL_EXCLUDE, VPOOL_INCLUDE};
38
#define VPOOL_TAIL UINT_MAX
39
40
void
vpool_init(
struct
vpool
*pool,
size_t
blksize,
size_t
limit);
41
void
vpool_final(
struct
vpool
*pool);
42
43
void
vpool_reset(
struct
vpool
*pool);
44
void
vpool_wipe(
struct
vpool
*pool);
45
46
void
* vpool_insert(
struct
vpool
*pool,
47
size_t
where,
void
*data,
size_t
datsize);
48
void
* vpool_expand(
struct
vpool
*pool,
size_t
where,
size_t
size);
49
50
int
vpool_truncate(
struct
vpool
*pool,
51
size_t
where,
size_t
size,
enum
vpool_trunc how);
52
53
#define vpool_is_empty(pool) ((pool)->v_off == 0)
54
#define vpool_get_buf(pool) ((pool)->v_buf)
55
#define vpool_get_length(pool) ((pool)->v_off)
56
#define vpool_get_error(pool) ((pool)->v_lasterr)
57
58
void
vpool_export(
struct
vpool
*pool,
void
**buf,
size_t
*size);
59
60
#endif
/* !_VPOOL_H_ */
vpool
Definition:
vpool.h:26
src
vpool.h
Generated by
1.8.13