Harald Welte | 898ffef | 2017-05-15 21:37:34 +0200 | [diff] [blame] | 1 | /* overly simplistic talloc replacement for deeply embedded |
| 2 | * microcontrollers. Obviously this has none of the properties of real |
| 3 | * talloc, it is particualrly not hierarchical at all */ |
| 4 | |
| 5 | |
| 6 | #include "talloc.h" |
| 7 | #include <string.h> |
| 8 | |
| 9 | void *_talloc_zero(const void *ctx, size_t size, const char *name) |
| 10 | { |
| 11 | void *p = pseudotalloc_malloc(size); |
| 12 | if (!p) |
| 13 | return NULL; |
| 14 | memset(p, 0, size); |
| 15 | return p; |
| 16 | } |
| 17 | |
| 18 | int _talloc_free(void *ptr, const char *location) |
| 19 | { |
| 20 | pseudotalloc_free(ptr); |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | void *talloc_named_const(const void *context, size_t size, const char *name) |
| 25 | { |
| 26 | return pseudotalloc_malloc(size); |
| 27 | } |
| 28 | |
| 29 | void talloc_set_name_const(const void *ptr, const char *name) |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | char *talloc_strdup(const void *context, const char *p) |
| 34 | { |
| 35 | char *ptr; |
| 36 | size_t len; |
| 37 | |
| 38 | if (!p) |
| 39 | return NULL; |
| 40 | len = strlen(p); |
| 41 | |
| 42 | ptr = talloc_size(context, len+1); |
| 43 | if (!ptr) |
| 44 | return NULL; |
| 45 | memcpy(ptr, p, len+1); |
| 46 | |
| 47 | return ptr; |
| 48 | } |
| 49 | |
| 50 | void *talloc_pool(const void *context, size_t size) |
| 51 | { |
| 52 | return (void *) context; |
| 53 | } |
| 54 | |
| 55 | void *_talloc_array(const void *ctx, size_t el_size, unsigned count, const char *name) |
| 56 | { |
| 57 | return talloc_size(ctx, el_size * count); |
| 58 | } |
| 59 | |
| 60 | void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name) |
| 61 | { |
| 62 | return talloc_zero_size(ctx, el_size * count); |
| 63 | } |