blob: fe7f1edcb4d303a7fff13bc42dba31d5fc7bc2ea [file] [log] [blame]
Harald Welte898ffef2017-05-15 21:37:34 +02001/* 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
9void *_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
18int _talloc_free(void *ptr, const char *location)
19{
20 pseudotalloc_free(ptr);
21 return 0;
22}
23
24void *talloc_named_const(const void *context, size_t size, const char *name)
25{
26 return pseudotalloc_malloc(size);
27}
28
29void talloc_set_name_const(const void *ptr, const char *name)
30{
31}
32
33char *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
50void *talloc_pool(const void *context, size_t size)
51{
52 return (void *) context;
53}
54
55void *_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
60void *_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}