#include #include #include #include "dat.h" #include "fns.h" void* emalloc(ulong n) { void *b; b = mallocz(n, 1); if(b == nil) sysfatal("out of memory allocating %lud: %r", n); setmalloctag(b, getcallerpc(&n)); return b; } void* erealloc(void *a, ulong n) { void *b; b = realloc(a, n); if(b == nil) sysfatal("out of memory re-allocating %lud: %r", n); setrealloctag(b, getcallerpc(&a)); return b; } char* estrdup(const char *s) { char *b; b = strdup(s); if(b == nil) sysfatal("strdup: %r"); setmalloctag(b, getcallerpc(&s)); return b; } void hexdump(uchar *p, uint len) { unsigned char *line = p; int i, thisline, offset = 0; while (offset < len) { fprint(2, "%04x ", offset); thisline = len - offset; if (thisline > 16) thisline = 16; for (i = 0; i < thisline; i++) fprint(2, "%02x ", line[i]); for (; i < 16; i++) fprint(2, " "); for (i = 0; i < thisline; i++) fprint(2, "%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.'); fprint(2, "\n"); offset += thisline; line += thisline; } } static int killpid[32]; static int nkillpid; void atexitkiller(void) { int i, pid; pid = getpid(); for(i=0; i