]> andersk Git - openssh.git/blame - xmalloc.c
- Add recommendation to use GNU make to INSTALL document
[openssh.git] / xmalloc.c
CommitLineData
8efc0c15 1/*
2
3xmalloc.c
4
5Author: Tatu Ylonen <ylo@cs.hut.fi>
6
7Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8 All rights reserved
9
10Created: Mon Mar 20 21:23:10 1995 ylo
11
12Versions of malloc and friends that check their results, and never return
13failure (they call fatal if they encounter an error).
14
15*/
16
17#include "includes.h"
18RCSID("$Id$");
19
20#include "ssh.h"
21
22void *xmalloc(size_t size)
23{
24 void *ptr = malloc(size);
25 if (ptr == NULL)
26 fatal("xmalloc: out of memory (allocating %d bytes)", (int)size);
27 return ptr;
28}
29
30void *xrealloc(void *ptr, size_t new_size)
31{
32 void *new_ptr;
33
34 if (ptr == NULL)
35 fatal("xrealloc: NULL pointer given as argument");
36 new_ptr = realloc(ptr, new_size);
37 if (new_ptr == NULL)
38 fatal("xrealloc: out of memory (new_size %d bytes)", (int)new_size);
39 return new_ptr;
40}
41
42void xfree(void *ptr)
43{
44 if (ptr == NULL)
45 fatal("xfree: NULL pointer given as argument");
46 free(ptr);
47}
48
49char *xstrdup(const char *str)
50{
51 int len = strlen(str) + 1;
52
53 char *cp = xmalloc(len);
54 strlcpy(cp, str, len);
55 return cp;
56}
This page took 0.053969 seconds and 5 git commands to generate.