#include "rc.h" void fatal(char *msg, ...) { va_list args; vfprintf(stderr, msg, args); va_end(args); abort(); } void* emalloc(uintptr n) { void *p; if(!(p = malloc(n))) fatal("out of memory: can't allocate %d bytes", n); memset(p, 0, n); return p; } void* erealloc(void *p, uintptr n) { void *r; if(!(r = realloc(p,n))) fatal("out of memory: can't reallocate %d bytes", n); return r; } void efree(void *p) { if(p) free(p); // TODO: log the double free } char *bp; static void iacvt(int n) { if(n<0){ *bp++='-'; n=-n; /* doesn't work for n==-inf */ } if(n/10) iacvt(n/10); *bp++=n%10+'0'; } void itoa(char *s, long n) { bp = s; iacvt(n); *bp='\0'; }