summaryrefslogtreecommitdiffstats
path: root/src/util/allocators/stdalloc.c
blob: f2d72a7e6c953d2ad01fb744938d16e34f19bcbe (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
/*
 * Copyright (C) the libgit2 contributors. All rights reserved.
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */

#include "stdalloc.h"

static void *stdalloc__malloc(size_t len, const char *file, int line)
{
	GIT_UNUSED(file);
	GIT_UNUSED(line);

#ifdef GIT_DEBUG_STRICT_ALLOC
	if (!len)
		return NULL;
#endif

	return malloc(len);
}

static void *stdalloc__realloc(void *ptr, size_t size, const char *file, int line)
{
	GIT_UNUSED(file);
	GIT_UNUSED(line);

#ifdef GIT_DEBUG_STRICT_ALLOC
	if (!size)
		return NULL;
#endif

	return realloc(ptr, size);
}

static void stdalloc__free(void *ptr)
{
	free(ptr);
}

int git_stdalloc_init_allocator(git_allocator *allocator)
{
	allocator->gmalloc = stdalloc__malloc;
	allocator->grealloc = stdalloc__realloc;
	allocator->gfree = stdalloc__free;
	return 0;
}