DUMB SHIT MISCHIEF AND MALFEASANCE EDITION
😲 Sticker
When the story you're reading reveals over half way in that the first person narrator is unreliable and is maybe going through hypothermia induced fever dream psychosis and that the bird she buried is maybe not dead or buried
I should remove
xalloc functions from my code already. Error checking sucks but it sucks less than having the program exit "randomly"// The code, if you were wondering
#define XALLOC_EXIT(msg, ...) do {\
if(!___VXGG___XALLOC_EXIT_ON_ERROR___)\
abort();\
if(!___VXGG___VERBOSE_ERRORS___)\
exit(EXIT_FAILURE);\
error(EXIT_FAILURE, errno, (msg)__VA_ARGS__);\
exit(EXIT_FAILURE); /* Makes gcc happy */\
} while (0)
enum XALLOC_TYPE {
XALLOC_INVAL, // Default when unset
XALLOC_MALLOC,
XALLOC_CALLOC,
XALLOC_REALLOC,
XALLOC_2BIG // Out of range
};
void * xalloc(size_t nmemb, size_t size, enum XALLOC_TYPE actype, void *ptr) {
if(actype <= XALLOC_INVAL || actype >= XALLOC_2BIG)
RETURNWERR(EINVAL, NULL);
void *mem = NULL;
switch(actype) {
case XALLOC_MALLOC:
mem = malloc(nmemb * size);
break;
case XALLOC_CALLOC:
mem = calloc(nmemb, size);
break;
case XALLOC_REALLOC:
mem = realloc(ptr, nmemb * size);
break;
default:
XALLOC_EXIT("<xalloc> An unknown alloc type was passed, which shouldn't be possible", );
}
if(!mem)
XALLOC_EXIT("<xalloc> Could not allocate memory", );
return mem;
}
void * xmalloc(size_t size) {
return xalloc(size, 1, XALLOC_MALLOC, NULL);
}
void * xcalloc(size_t nmemb, size_t size) {
return xalloc(nmemb, size, XALLOC_CALLOC, NULL);
}
void * xreallocarray(void *ptr, size_t nmemb, size_t size) {
return xalloc(nmemb, size, XALLOC_REALLOC, ptr);
}