1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <string.h> #include <stdlib.h> #include "debug.h" void *xmalloc(size_t size) { void *p; p = malloc(size); if (p == NULL) sys_err("malloc %zd bytes", size); return p; } char *xstrdup(const char *s) { int len; len = strlen(s) + 1; return memcpy(xmalloc(len), s, len); }