]> andersk Git - openssh.git/blame - xmalloc.c
- (djm) Fix server not exiting with jobs in background.
[openssh.git] / xmalloc.c
CommitLineData
8efc0c15 1/*
5260325f 2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
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).
8 */
8efc0c15 9
10#include "includes.h"
74fc9186 11RCSID("$OpenBSD: xmalloc.c,v 1.7 2000/06/20 01:39:45 markus Exp $");
8efc0c15 12
13#include "ssh.h"
14
5260325f 15void *
16xmalloc(size_t size)
8efc0c15 17{
5260325f 18 void *ptr = malloc(size);
19 if (ptr == NULL)
20 fatal("xmalloc: out of memory (allocating %d bytes)", (int) size);
21 return ptr;
8efc0c15 22}
23
5260325f 24void *
25xrealloc(void *ptr, size_t new_size)
8efc0c15 26{
5260325f 27 void *new_ptr;
28
29 if (ptr == NULL)
30 fatal("xrealloc: NULL pointer given as argument");
31 new_ptr = realloc(ptr, new_size);
32 if (new_ptr == NULL)
33 fatal("xrealloc: out of memory (new_size %d bytes)", (int) new_size);
34 return new_ptr;
8efc0c15 35}
36
6ae2364d 37void
5260325f 38xfree(void *ptr)
8efc0c15 39{
5260325f 40 if (ptr == NULL)
41 fatal("xfree: NULL pointer given as argument");
42 free(ptr);
8efc0c15 43}
44
5260325f 45char *
46xstrdup(const char *str)
8efc0c15 47{
5260325f 48 int len = strlen(str) + 1;
8efc0c15 49
5260325f 50 char *cp = xmalloc(len);
51 strlcpy(cp, str, len);
52 return cp;
8efc0c15 53}
This page took 0.070984 seconds and 5 git commands to generate.