diff options
author | Harald Welte <laforge@gnumonks.org> | 2017-05-15 21:37:34 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-05-17 15:15:52 +0100 |
commit | 898ffefde4198a23a92810a9cf39ff6846f3bb39 (patch) | |
tree | ab4f79425d35ade4b542b0b6d57b58992408321f /src/pseudotalloc/pseudotalloc.c | |
parent | 7f24c155f5acd898cd49f9f429500461fa4fd8a5 (diff) |
add libpseudotalloc as super-simplistic talloc replacement
In tightly embedded builds (--enable-embedded), we want the ability to
replace talloc with a very simple heap allocator to avoid the complexity
of talloc without modifying all our code that assumes talloc.
This will break the hierarchical notion of the allocator, but
libosmo{core,gsm,coding,codec} don't rely on that anyway.
Change-Id: Ie341034076f242a813f081919dd09d845775ad35
Diffstat (limited to 'src/pseudotalloc/pseudotalloc.c')
-rw-r--r-- | src/pseudotalloc/pseudotalloc.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/pseudotalloc/pseudotalloc.c b/src/pseudotalloc/pseudotalloc.c new file mode 100644 index 00000000..fe7f1edc --- /dev/null +++ b/src/pseudotalloc/pseudotalloc.c @@ -0,0 +1,63 @@ +/* overly simplistic talloc replacement for deeply embedded + * microcontrollers. Obviously this has none of the properties of real + * talloc, it is particualrly not hierarchical at all */ + + +#include "talloc.h" +#include <string.h> + +void *_talloc_zero(const void *ctx, size_t size, const char *name) +{ + void *p = pseudotalloc_malloc(size); + if (!p) + return NULL; + memset(p, 0, size); + return p; +} + +int _talloc_free(void *ptr, const char *location) +{ + pseudotalloc_free(ptr); + return 0; +} + +void *talloc_named_const(const void *context, size_t size, const char *name) +{ + return pseudotalloc_malloc(size); +} + +void talloc_set_name_const(const void *ptr, const char *name) +{ +} + +char *talloc_strdup(const void *context, const char *p) +{ + char *ptr; + size_t len; + + if (!p) + return NULL; + len = strlen(p); + + ptr = talloc_size(context, len+1); + if (!ptr) + return NULL; + memcpy(ptr, p, len+1); + + return ptr; +} + +void *talloc_pool(const void *context, size_t size) +{ + return (void *) context; +} + +void *_talloc_array(const void *ctx, size_t el_size, unsigned count, const char *name) +{ + return talloc_size(ctx, el_size * count); +} + +void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name) +{ + return talloc_zero_size(ctx, el_size * count); +} |