summaryrefslogtreecommitdiffstats
path: root/src/util/allocators/stdalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/allocators/stdalloc.c')
-rw-r--r--src/util/allocators/stdalloc.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/util/allocators/stdalloc.c b/src/util/allocators/stdalloc.c
new file mode 100644
index 0000000..f2d72a7
--- /dev/null
+++ b/src/util/allocators/stdalloc.c
@@ -0,0 +1,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;
+}