]> git.ipfire.org Git - thirdparty/git.git/blob - reftable/publicbasics.c
git-config: fix misworded --type=path explanation
[thirdparty/git.git] / reftable / publicbasics.c
1 /*
2 Copyright 2020 Google LLC
3
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file or at
6 https://developers.google.com/open-source/licenses/bsd
7 */
8
9 #include "reftable-malloc.h"
10
11 #include "basics.h"
12 #include "system.h"
13
14 static void *(*reftable_malloc_ptr)(size_t sz);
15 static void *(*reftable_realloc_ptr)(void *, size_t);
16 static void (*reftable_free_ptr)(void *);
17
18 void *reftable_malloc(size_t sz)
19 {
20 if (reftable_malloc_ptr)
21 return (*reftable_malloc_ptr)(sz);
22 return malloc(sz);
23 }
24
25 void *reftable_realloc(void *p, size_t sz)
26 {
27 if (reftable_realloc_ptr)
28 return (*reftable_realloc_ptr)(p, sz);
29 return realloc(p, sz);
30 }
31
32 void reftable_free(void *p)
33 {
34 if (reftable_free_ptr)
35 reftable_free_ptr(p);
36 else
37 free(p);
38 }
39
40 void *reftable_calloc(size_t sz)
41 {
42 void *p = reftable_malloc(sz);
43 memset(p, 0, sz);
44 return p;
45 }
46
47 void reftable_set_alloc(void *(*malloc)(size_t),
48 void *(*realloc)(void *, size_t), void (*free)(void *))
49 {
50 reftable_malloc_ptr = malloc;
51 reftable_realloc_ptr = realloc;
52 reftable_free_ptr = free;
53 }
54
55 int hash_size(uint32_t id)
56 {
57 switch (id) {
58 case 0:
59 case GIT_SHA1_FORMAT_ID:
60 return GIT_SHA1_RAWSZ;
61 case GIT_SHA256_FORMAT_ID:
62 return GIT_SHA256_RAWSZ;
63 }
64 abort();
65 }