2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * Created: Mon Mar 20 21:23:10 1995 ylo
6 * Versions of malloc and friends that check their results, and never return
7 * failure (they call fatal if they encounter an error).
11 RCSID("$OpenBSD: xmalloc.c,v 1.7 2000/06/20 01:39:45 markus Exp $");
18 void *ptr = malloc(size);
20 fatal("xmalloc: out of memory (allocating %d bytes)", (int) size);
25 xrealloc(void *ptr, size_t new_size)
30 fatal("xrealloc: NULL pointer given as argument");
31 new_ptr = realloc(ptr, new_size);
33 fatal("xrealloc: out of memory (new_size %d bytes)", (int) new_size);
41 fatal("xfree: NULL pointer given as argument");
46 xstrdup(const char *str)
48 int len = strlen(str) + 1;
50 char *cp = xmalloc(len);
51 strlcpy(cp, str, len);