Commit fdaa9389 authored by Ulrich Huber's avatar Ulrich Huber Committed by Oliver Horst
Browse files

[add] Added crude implementation of realloc

parent d468ef18
......@@ -4,5 +4,6 @@
#include <sys/malloc.h>
void *calloc(size_t nmemb, size_t size);
void *realloc(void *ptr, size_t size);
#endif //TOKI_MALLOC_H
......@@ -8,5 +8,6 @@ target_sources(
"${CMAKE_CURRENT_LIST_DIR}/atoi.c"
"${CMAKE_CURRENT_LIST_DIR}/calloc.c"
"${CMAKE_CURRENT_LIST_DIR}/rand.c"
"${CMAKE_CURRENT_LIST_DIR}/realloc.c"
"${CMAKE_CURRENT_LIST_DIR}/strtol.c"
)
......@@ -4,6 +4,7 @@ Files:
- atoi.c
- calloc.c
- rand.c
- realloc.c
BSD with Attribution License
......
#include <malloc.h>
#include <string.h>
void *realloc(void *ptr, size_t size) {
/*
* Very very crude implementation of realloc.
* Better would be if the current block can be extended.
*/
void *new_ptr = malloc(size);
memmove(new_ptr, ptr, size);
free(ptr);
return new_ptr;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment