From cda4527cefc55f4d9ade17cca717f60214b82062 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 29 Jun 2020 12:20:31 -0400 Subject: outline functions --- src/mapalloc.c | 35 +++++++++++++++++++++++++++++++++++ src/mapalloc.h | 11 +++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/mapalloc.c create mode 100644 src/mapalloc.h (limited to 'src') diff --git a/src/mapalloc.c b/src/mapalloc.c new file mode 100644 index 0000000..bde39f9 --- /dev/null +++ b/src/mapalloc.c @@ -0,0 +1,35 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include + +#include "mapalloc.h" + +void *map_calloc(size_t nelem, size_t elsize) +{ + size_t n = nelem * elsize; + if (n < nelem || n < elsize) { + /* overflow */ + return NULL; + } + void *ptr = map_malloc(n); + memset(ptr, 0, n); + return ptr; +} + +void *map_malloc(size_t n) +{ +} + +void *map_realloc(void *ptr, size_t n) +{ + if (ptr == NULL) { + return map_malloc(n); + } +} + +void map_free(void *ptr) +{ + if (ptr == NULL) { + return; + } +} diff --git a/src/mapalloc.h b/src/mapalloc.h new file mode 100644 index 0000000..f4a4434 --- /dev/null +++ b/src/mapalloc.h @@ -0,0 +1,11 @@ +#ifndef MAPALLOC_H +#define MAPALLOC_H + +#include /* for the definition of size_t */ + +void *map_malloc(size_t n); +void *map_calloc(size_t nelem, size_t elsize); +void *map_realloc(void *ptr, size_t n); +void map_free(void *ptr); + +#endif -- cgit v1.2.1