aboutsummaryrefslogtreecommitdiff
path: root/allocator.c
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2020-10-29 16:33:23 +0100
committerThomas Schmucker <ts@its1.de>2020-10-29 16:33:23 +0100
commit034e99bf9e1621ec413a87ee5277e11210a03ee1 (patch)
treeae8024cb7a4f453db1742d6850b7e43b7c9b2cc9 /allocator.c
parentb0749a900f214f11d89a34bd605b66f1b0ed1d19 (diff)
downloaddata-structures-034e99bf9e1621ec413a87ee5277e11210a03ee1.tar.gz
data-structures-034e99bf9e1621ec413a87ee5277e11210a03ee1.tar.bz2
data-structures-034e99bf9e1621ec413a87ee5277e11210a03ee1.zip
clang-format
Diffstat (limited to 'allocator.c')
-rw-r--r--allocator.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/allocator.c b/allocator.c
index c498bc7..6d13a17 100644
--- a/allocator.c
+++ b/allocator.c
@@ -1,6 +1,7 @@
1#include <stdlib.h>
2#include "allocator.h" 1#include "allocator.h"
3 2
3#include <stdlib.h>
4
4/* Interface Code */ 5/* Interface Code */
5static void * 6static void *
6default_allocate(struct its1_allocator *allocator, size_t n) 7default_allocate(struct its1_allocator *allocator, size_t n)
@@ -17,7 +18,7 @@ default_deallocate(struct its1_allocator *allocator, void *ptr)
17} 18}
18 19
19struct its1_allocator its1_default_allocator = { 20struct its1_allocator its1_default_allocator = {
20 .allocate = &default_allocate, 21 .allocate = &default_allocate,
21 .deallocate = &default_deallocate 22 .deallocate = &default_deallocate
22}; 23};
23 24
@@ -27,7 +28,7 @@ struct its1_allocator its1_default_allocator = {
27void * 28void *
28its1_malloc(struct its1_allocator *allocator, size_t n) 29its1_malloc(struct its1_allocator *allocator, size_t n)
29{ 30{
30 if (allocator == NULL) { 31 if ( allocator == NULL ) {
31 allocator = &its1_default_allocator; 32 allocator = &its1_default_allocator;
32 } 33 }
33 34
@@ -37,7 +38,7 @@ its1_malloc(struct its1_allocator *allocator, size_t n)
37void 38void
38its1_free(struct its1_allocator *allocator, void *ptr) 39its1_free(struct its1_allocator *allocator, void *ptr)
39{ 40{
40 if (allocator == NULL) { 41 if ( allocator == NULL ) {
41 allocator = &its1_default_allocator; 42 allocator = &its1_default_allocator;
42 } 43 }
43 44
@@ -48,11 +49,11 @@ char *
48its1_strdup(struct its1_allocator *allocator, const char *str) 49its1_strdup(struct its1_allocator *allocator, const char *str)
49{ 50{
50 size_t n; 51 size_t n;
51 char *dest; 52 char * dest;
52 53
53 n = strlen(str) + 1; 54 n = strlen(str) + 1;
54 dest = its1_malloc(allocator, n); 55 dest = its1_malloc(allocator, n);
55 if (dest != NULL) { 56 if ( dest != NULL ) {
56 memcpy(dest, str, n); 57 memcpy(dest, str, n);
57 } 58 }
58 59
@@ -65,11 +66,14 @@ its1_malloc_zero(struct its1_allocator *allocator, size_t n)
65 void *ptr; 66 void *ptr;
66 67
67 ptr = its1_malloc(allocator, n); 68 ptr = its1_malloc(allocator, n);
68 if (ptr != NULL) { 69 if ( ptr != NULL ) {
69 memset(ptr, 0, n); 70 memset(ptr, 0, n);
70 } 71 }
71 72
72 return ptr; 73 return ptr;
73} 74}
74 75
75int main() {} 76int
77main()
78{
79}