Add basic list implementation
This commit is contained in:
26
src/list/typed_list.c
Normal file
26
src/list/typed_list.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "list/typed_list.h"
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
list_void_t *_create_list(u64 size, u64 count) {
|
||||
list_void_t *list = (list_void_t *)_alloc_for_list(sizeof(list_void_t));
|
||||
if (!list) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
list->items = (void *)_alloc_for_list(size * count);
|
||||
if (!list->items) {
|
||||
munmap(list, sizeof(list_void_t));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
list->capacity = count;
|
||||
list->count = 0;
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void *_alloc_for_list(u64 size) {
|
||||
return mmap(NULL, size, PROT_READ | PROT_WRITE,
|
||||
MAP_ANON | MAP_NORESERVE | MAP_SHARED, -1, 0);
|
||||
}
|
||||
Reference in New Issue
Block a user