2019-05-30 21:46:22 -05:00
|
|
|
// 30 may 2019
|
|
|
|
// requires: alloc_header.h
|
|
|
|
|
2019-05-30 22:23:02 -05:00
|
|
|
#include "start.h"
|
2019-05-30 22:11:08 -05:00
|
|
|
|
2019-06-01 19:20:11 -05:00
|
|
|
#include "printfwarn_header.h"
|
|
|
|
sharedbitsPrintfFunc(
|
|
|
|
extern void sharedbitsPrefixName(InternalError)(const char *fmt, ...),
|
|
|
|
1, 2);
|
2019-05-30 22:11:08 -05:00
|
|
|
|
|
|
|
void *sharedbitsPrefixName(Alloc)(size_t n, const char *what)
|
|
|
|
{
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
p = malloc(n);
|
2020-02-09 12:37:45 -06:00
|
|
|
if (p == NULL) {
|
2019-05-30 22:11:08 -05:00
|
|
|
sharedbitsPrefixName(InternalError)("memory exhausted allocating %s", what);
|
2020-02-09 12:37:45 -06:00
|
|
|
abort(); // TODO handle more gracefully somehow
|
|
|
|
}
|
2019-05-30 22:11:08 -05:00
|
|
|
memset(p, 0, n);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *sharedbitsPrefixName(Realloc)(void *p, size_t nOld, size_t nNew, const char *what)
|
|
|
|
{
|
|
|
|
p = realloc(p, nNew);
|
2020-02-09 12:37:45 -06:00
|
|
|
if (p == NULL) {
|
2019-05-30 22:11:08 -05:00
|
|
|
sharedbitsPrefixName(InternalError)("memory exhausted reallocating %s", what);
|
2020-02-09 12:37:45 -06:00
|
|
|
abort(); // TODO handle more gracefully somehow
|
|
|
|
}
|
2019-05-30 22:11:08 -05:00
|
|
|
if (nNew > nOld)
|
|
|
|
memset(((uint8_t *) p) + nOld, 0, nNew - nOld);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sharedbitsPrefixName(Free)(void *p)
|
|
|
|
{
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
2019-05-30 22:23:02 -05:00
|
|
|
#include "end.h"
|