diff options
| -rw-r--r-- | allocator.c | 22 |
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 */ |
| 5 | static void * | 6 | static void * |
| 6 | default_allocate(struct its1_allocator *allocator, size_t n) | 7 | default_allocate(struct its1_allocator *allocator, size_t n) |
| @@ -17,7 +18,7 @@ default_deallocate(struct its1_allocator *allocator, void *ptr) | |||
| 17 | } | 18 | } |
| 18 | 19 | ||
| 19 | struct its1_allocator its1_default_allocator = { | 20 | struct 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 = { | |||
| 27 | void * | 28 | void * |
| 28 | its1_malloc(struct its1_allocator *allocator, size_t n) | 29 | its1_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) | |||
| 37 | void | 38 | void |
| 38 | its1_free(struct its1_allocator *allocator, void *ptr) | 39 | its1_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 * | |||
| 48 | its1_strdup(struct its1_allocator *allocator, const char *str) | 49 | its1_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 | ||
| 75 | int main() {} | 76 | int |
| 77 | main() | ||
| 78 | { | ||
| 79 | } | ||
