2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * Versions of malloc and friends that check their results, and never return
6 * failure (they call fatal if they encounter an error).
8 * As far as I am concerned, the code I have written for this software
9 * can be used freely for any purpose. Any derived versions of this
10 * software must be clearly marked as such, and if the derived work is
11 * incompatible with the protocol description in the RFC file, it must be
12 * called by a name other than "ssh" or "Secure Shell".
16 RCSID("$OpenBSD: xmalloc.c,v 1.10 2001/01/28 20:53:21 stevesk Exp $");
24 void *ptr = malloc(size);
26 fatal("xmalloc: out of memory (allocating %d bytes)", (int) size);
31 xrealloc(void *ptr, size_t new_size)
36 fatal("xrealloc: NULL pointer given as argument");
37 new_ptr = realloc(ptr, new_size);
39 fatal("xrealloc: out of memory (new_size %d bytes)", (int) new_size);
47 fatal("xfree: NULL pointer given as argument");
52 xstrdup(const char *str)
54 size_t len = strlen(str) + 1;
56 char *cp = xmalloc(len);
57 strlcpy(cp, str, len);