]> git.proxmox.com Git - libgit2.git/blob - src/alloc.c
Merge branch 'debian/experimental' into debian/sid
[libgit2.git] / src / alloc.c
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7
8 #include "alloc.h"
9
10 #include "allocators/stdalloc.h"
11 #include "allocators/win32_crtdbg.h"
12
13 git_allocator git__allocator;
14
15 static int setup_default_allocator(void)
16 {
17 #if defined(GIT_MSVC_CRTDBG)
18 return git_win32_crtdbg_init_allocator(&git__allocator);
19 #else
20 return git_stdalloc_init_allocator(&git__allocator);
21 #endif
22 }
23
24 int git_allocator_global_init(void)
25 {
26 /*
27 * We don't want to overwrite any allocator which has been set before
28 * the init function is called.
29 */
30 if (git__allocator.gmalloc != NULL)
31 return 0;
32
33 return setup_default_allocator();
34 }
35
36 int git_allocator_setup(git_allocator *allocator)
37 {
38 if (!allocator)
39 return setup_default_allocator();
40
41 memcpy(&git__allocator, allocator, sizeof(*allocator));
42 return 0;
43 }