-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpool.h
More file actions
53 lines (37 loc) · 1.37 KB
/
pool.h
File metadata and controls
53 lines (37 loc) · 1.37 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
46
47
48
49
50
51
52
53
#ifndef POOL_H
#define POOL_H
#ifndef _AMALGAMATE_
#include <stddef.h>
#include <stdarg.h>
#endif
struct pool_unit {
void *heap;
struct pool_unit *next;
};
struct pool {
size_t usiz; /// Used size
size_t asiz; /// Allocated size
struct pool_unit *unit; /// Current heap unit
void *user_data; /// Associated user data
char *heap; /// Current pool heap ptr
void (*on_pool_destroy)(struct pool*); /// Called when pool destroyed
};
struct pool* pool_create_empty(void);
struct pool* pool_create_preallocated(size_t);
struct pool* pool_create(void (*)(struct pool*));
void pool_destroy(struct pool*);
void* pool_alloc(struct pool*, size_t siz);
void* pool_calloc(struct pool*, size_t siz);
char* pool_strdup(struct pool*, const char*);
char* pool_strndup(struct pool*, const char*, size_t len);
char* pool_printf_va(struct pool*, const char *format, va_list va);
char* pool_printf(struct pool*, const char*, ...) __attribute__((format(__printf__, 2, 3)));
const char** pool_split_string(
struct pool *pool,
const char *haystack,
const char *split_chars,
int ignore_whitespace);
const char** pool_split(
struct pool*, const char *split_chars, int ignore_ws, const char *fmt,
...) __attribute__((format(__printf__, 4, 5)));
#endif