#define _GNU_SOURCE #include #include #include #include "global.h" #include "memory.h" void* check_after_allocation(const char *func,size_t num,size_t sz,void *ptr){ if(ptr==NULL){ fprintf(stderr,"Allocation failed: %s(%zu * %zuB = %zu)",func,num,sz,num*sz); exit(1); } return ptr; } void* check_after_allocation_str(const char *func,void *ptr){ if(ptr==NULL){ fprintf(stderr,"Allocation failed: %s()",func); exit(1); } return ptr; } __attribute__((format (printf, 2, 3))) int memory_asprintf_wrapper(char **ret,const char *format,...){ assert(ret!=NULL); va_list ap; va_start(ap,format); int len=vasprintf(ret,format,ap); va_end(ap); check_after_allocation_str("asprintf",*ret); return len; }