5 Author: Tatu Ylonen <ylo@cs.hut.fi>
7 Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
10 Created: Mon Mar 20 21:23:10 1995 ylo
12 Versions of malloc and friends that check their results, and never return
13 failure (they call fatal if they encounter an error).
22 void *xmalloc(size_t size)
24 void *ptr = malloc(size);
26 fatal("xmalloc: out of memory (allocating %d bytes)", (int)size);
30 void *xrealloc(void *ptr, size_t new_size)
35 fatal("xrealloc: NULL pointer given as argument");
36 new_ptr = realloc(ptr, new_size);
38 fatal("xrealloc: out of memory (new_size %d bytes)", (int)new_size);
45 fatal("xfree: NULL pointer given as argument");
49 char *xstrdup(const char *str)
51 int len = strlen(str) + 1;
53 char *cp = xmalloc(len);
54 strlcpy(cp, str, len);