summaryrefslogtreecommitdiffstats
path: root/src/lib/imem.c
blob: a991a922cd17020facd3051c35e93b6f65d247e2 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */

#include "lib.h"

pool_t default_pool = &static_system_pool;

void *i_malloc(size_t size)
{
	return p_malloc(default_pool, size);
}

void *i_realloc(void *mem, size_t old_size, size_t new_size)
{
	return p_realloc(default_pool, mem, old_size, new_size);
}

char *i_strdup(const char *str)
{
	return p_strdup(default_pool, str);
}

void *i_memdup(const void *data, size_t size)
{
	return p_memdup(default_pool, data, size);
}

char *i_strdup_empty(const char *str)
{
	return p_strdup_empty(default_pool, str);
}

char *i_strdup_until(const void *str, const void *end)
{
	return p_strdup_until(default_pool, str, end);
}

char *i_strndup(const void *str, size_t max_chars)
{
	i_assert(str != NULL);
	return p_strndup(default_pool, str, max_chars);
}

char *i_strdup_printf(const char *format, ...)
{
	va_list args;
	char *ret;

	va_start(args, format);
	ret = p_strdup_vprintf(default_pool, format, args);
	va_end(args);
	return ret;
}

char *i_strdup_vprintf(const char *format, va_list args)
{
	return p_strdup_vprintf(default_pool, format, args);
}

char *i_strconcat(const char *str1, ...)
{
	va_list args;
	char *ret;
	size_t len;

	i_assert(str1 != NULL);

	va_start(args, str1);

	T_BEGIN {
		const char *temp = vstrconcat(str1, args, &len);
		t_buffer_alloc(len);
		ret = p_malloc(default_pool, len);
		memcpy(ret, temp, len);
	} T_END;

	va_end(args);
	return ret;
}