cutil redirect std functions to cu_ holders, array 4
This commit is contained in:
parent
a19e5460c4
commit
311f00b374
5 changed files with 32 additions and 4 deletions
15
array.c
15
array.c
|
|
@ -29,7 +29,20 @@ void array_clear(array_t* array)
|
||||||
array->align = 0;
|
array->align = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint array_align(array_t* array, uint count)
|
||||||
|
{
|
||||||
|
return (count / array->align + !!(count % array->align)) * array->align;
|
||||||
|
}
|
||||||
|
|
||||||
void array_push(array_t* array, const void* data)
|
void array_push(array_t* array, const void* data)
|
||||||
{
|
{
|
||||||
|
if (!(array->count % array->align))
|
||||||
|
array_alloc(array, array->count + 1);
|
||||||
|
else array->count++;
|
||||||
|
cu_memcpy(array_last(array), data, array->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void array_pop(array_t* array, void* src)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
5
array.h
5
array.h
|
|
@ -14,6 +14,11 @@ void array_init(array_t* array, uint size, uint align);
|
||||||
void array_alloc(array_t* array, uint newCount);
|
void array_alloc(array_t* array, uint newCount);
|
||||||
void array_clear(array_t* array);
|
void array_clear(array_t* array);
|
||||||
|
|
||||||
|
#define array_at(array, i) ((uint8_t*)(array)->mem + (i)*(array)->size)
|
||||||
|
#define array_first(array) array_at(array, 0)
|
||||||
|
#define array_last(array) array_at(array, (array)->count - 1)
|
||||||
|
|
||||||
void array_push(array_t* array, const void* data);
|
void array_push(array_t* array, const void* data);
|
||||||
|
void array_pop(array_t* array, void* src);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
4
cutil.c
4
cutil.c
|
|
@ -1,5 +1,9 @@
|
||||||
#include "cutil.h"
|
#include "cutil.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
void* (*cu_malloc)(size_t) = CUTIL_MALLOC;
|
void* (*cu_malloc)(size_t) = CUTIL_MALLOC;
|
||||||
void* (*cu_realloc)(void*, size_t) = CUTIL_REALLOC;
|
void* (*cu_realloc)(void*, size_t) = CUTIL_REALLOC;
|
||||||
void* (*cu_free)(void*) = CUTIL_FREE;
|
void* (*cu_free)(void*) = CUTIL_FREE;
|
||||||
|
void* (*cu_memset)(void*,int,size_t) = CUTIL_MEMSET;
|
||||||
|
void* (*cu_memcpy)(void*,const void*,size_t) = CUTIL_MEMCPY;
|
||||||
|
void* (*cu_memmove)(void*,const void*,size_t) = CUTIL_MEMMOVE;
|
||||||
|
|
|
||||||
8
cutil.h
8
cutil.h
|
|
@ -7,9 +7,15 @@
|
||||||
#define CUTIL_MALLOC malloc
|
#define CUTIL_MALLOC malloc
|
||||||
#define CUTIL_REALLOC realloc
|
#define CUTIL_REALLOC realloc
|
||||||
#define CUTIL_FREE free
|
#define CUTIL_FREE free
|
||||||
|
#define CUTIL_MEMSET memset
|
||||||
|
#define CUTIL_MEMCPY memcpy
|
||||||
|
#define CUTIL_MEMMOVE memmove
|
||||||
|
|
||||||
extern void* (*cu_malloc)(size_t);
|
extern void* (*cu_malloc)(size_t);
|
||||||
extern void* (*cu_realloc)(void*, size_t);
|
extern void* (*cu_realloc)(void*, size_t);
|
||||||
extern void* (*cu_free)(void*);
|
extern void (*cu_free)(void*);
|
||||||
|
extern void* (*cu_memset)(void*,int,size_t);
|
||||||
|
extern void* (*cu_memcpy)(void*,const void*,size_t);
|
||||||
|
extern void* (*cu_memmove)(void*,const void*,size_t);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
4
list.c
4
list.c
|
|
@ -29,10 +29,10 @@ void list_add(list_t* list, uint size, void* data)
|
||||||
{
|
{
|
||||||
uint nodeSize = LIST_NODE_SIZE + size;
|
uint nodeSize = LIST_NODE_SIZE + size;
|
||||||
list_node_t* node = (list_node_t*)cu_malloc(nodeSize);
|
list_node_t* node = (list_node_t*)cu_malloc(nodeSize);
|
||||||
memset(node, '\0', nodeSize);
|
cu_memset(node, '\0', nodeSize);
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
memcpy((uint8_t*)node + LIST_NODE_SIZE, data, size);
|
cu_memcpy((uint8_t*)node + LIST_NODE_SIZE, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
list_node_t* last = list->last;
|
list_node_t* last = list->last;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue