2019-05-30 21:46:22 -05:00
|
|
|
// 30 may 2019
|
|
|
|
// requires: alloc_header.h
|
|
|
|
|
|
|
|
#ifndef sharedbitsPrefix
|
|
|
|
#error you must define sharedbitsPrefix before including this
|
|
|
|
#endif
|
2019-05-30 22:11:08 -05:00
|
|
|
#define sharedbitsPrefixMakeName(x, y) x ## y
|
2019-05-30 22:17:50 -05:00
|
|
|
#define sharedbitsPrefixExpandMakeName(x, y) sharedbitsPrefixMakeName(x, y)
|
|
|
|
#define sharedbitsPrefixName(Name) sharedbitsPrefixExpandMakeName(sharedbitsPrefix, Name)
|
2019-05-30 22:11:08 -05:00
|
|
|
|
|
|
|
extern void sharedbitsPrefixName(InternalError)(const char *fmt, ...);
|
|
|
|
|
|
|
|
void *sharedbitsPrefixName(Alloc)(size_t n, const char *what)
|
|
|
|
{
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
p = malloc(n);
|
|
|
|
if (p == NULL)
|
|
|
|
sharedbitsPrefixName(InternalError)("memory exhausted allocating %s", what);
|
|
|
|
memset(p, 0, n);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *sharedbitsPrefixName(Realloc)(void *p, size_t nOld, size_t nNew, const char *what)
|
|
|
|
{
|
|
|
|
p = realloc(p, nNew);
|
|
|
|
if (p == NULL)
|
|
|
|
sharedbitsPrefixName(InternalError)("memory exhausted reallocating %s", what);
|
|
|
|
if (nNew > nOld)
|
|
|
|
memset(((uint8_t *) p) + nOld, 0, nNew - nOld);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sharedbitsPrefixName(Free)(void *p)
|
|
|
|
{
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef sharedbitsPrefixName
|
2019-05-30 22:14:30 -05:00
|
|
|
#undef sharedbitsPrefixExpand
|
2019-05-30 22:11:08 -05:00
|
|
|
#undef sharedbitsPrefixMakeName
|